From 2f136d4ee1b00aaef1502de4e6904029278ee9a7 Mon Sep 17 00:00:00 2001 From: Emre ULUSOy Date: Tue, 14 Mar 2023 11:36:42 +0100 Subject: [PATCH] fix: compatibility with android 12 and up --- .../src/main/java/com/felhr/serialportexample/UsbService.java | 4 +++- .../src/main/java/com/felhr/examplestreams/UsbService.java | 4 +++- .../main/java/com/felhr/serialportexamplesync/UsbService.java | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/example/src/main/java/com/felhr/serialportexample/UsbService.java b/example/src/main/java/com/felhr/serialportexample/UsbService.java index 0efac01c..ac455957 100644 --- a/example/src/main/java/com/felhr/serialportexample/UsbService.java +++ b/example/src/main/java/com/felhr/serialportexample/UsbService.java @@ -230,8 +230,10 @@ private void setFilter() { * Request user permission. The response will be received in the BroadcastReceiver */ private void requestUserPermission() { + int flag = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) ? PendingIntent.FLAG_MUTABLE : 0; + Log.d(TAG, String.format("requestUserPermission(%X:%X)", device.getVendorId(), device.getProductId() ) ); - PendingIntent mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); + PendingIntent mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), flag); usbManager.requestPermission(device, mPendingIntent); } diff --git a/examplestreams/src/main/java/com/felhr/examplestreams/UsbService.java b/examplestreams/src/main/java/com/felhr/examplestreams/UsbService.java index f53ec19a..bb2fcd60 100644 --- a/examplestreams/src/main/java/com/felhr/examplestreams/UsbService.java +++ b/examplestreams/src/main/java/com/felhr/examplestreams/UsbService.java @@ -210,8 +210,10 @@ private void setFilter() { * Request user permission. The response will be received in the BroadcastReceiver */ private void requestUserPermission() { + int flag = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) ? PendingIntent.FLAG_MUTABLE : 0; + Log.d(TAG, String.format("requestUserPermission(%X:%X)", device.getVendorId(), device.getProductId() ) ); - PendingIntent mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); + PendingIntent mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), flag); usbManager.requestPermission(device, mPendingIntent); } diff --git a/examplesync/src/main/java/com/felhr/serialportexamplesync/UsbService.java b/examplesync/src/main/java/com/felhr/serialportexamplesync/UsbService.java index 2bccdcf4..4e9d4f70 100644 --- a/examplesync/src/main/java/com/felhr/serialportexamplesync/UsbService.java +++ b/examplesync/src/main/java/com/felhr/serialportexamplesync/UsbService.java @@ -240,8 +240,10 @@ private void setFilter() { * Request user permission. The response will be received in the BroadcastReceiver */ private void requestUserPermission() { + int flag = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) ? PendingIntent.FLAG_MUTABLE : 0; + Log.d(TAG, String.format("requestUserPermission(%X:%X)", device.getVendorId(), device.getProductId() ) ); - PendingIntent mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); + PendingIntent mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), flag); usbManager.requestPermission(device, mPendingIntent); }