diff --git a/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/AccessoryConnectionBootstrap.java b/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/AccessoryConnectionBootstrap.java index ef3c6ae3..e969c692 100644 --- a/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/AccessoryConnectionBootstrap.java +++ b/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/AccessoryConnectionBootstrap.java @@ -47,6 +47,7 @@ import java.io.OutputStream; import java.util.Collection; +import android.annotation.SuppressLint; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; @@ -267,9 +268,16 @@ private boolean tryOpen() { } } + @SuppressLint("UnspecifiedRegisterReceiverFlag") private void registerReceiver() { IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); - activity_.registerReceiver(this, filter); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + activity_.registerReceiver(this, filter, Context.RECEIVER_NOT_EXPORTED); + } else + activity_.registerReceiver(this, filter); + } else + activity_.registerReceiver(this, filter); } private void unregisterReceiver() { diff --git a/IOIOLibAndroidDevice/src/main/java/ioio/lib/android/device/DeviceConnectionBootstrap.java b/IOIOLibAndroidDevice/src/main/java/ioio/lib/android/device/DeviceConnectionBootstrap.java index 71b63c5b..0c264691 100644 --- a/IOIOLibAndroidDevice/src/main/java/ioio/lib/android/device/DeviceConnectionBootstrap.java +++ b/IOIOLibAndroidDevice/src/main/java/ioio/lib/android/device/DeviceConnectionBootstrap.java @@ -42,6 +42,7 @@ import java.util.Collection; import java.util.HashMap; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.PendingIntent; import android.content.BroadcastReceiver; @@ -484,11 +485,18 @@ private void checkPermission() { } } + @SuppressLint("UnspecifiedRegisterReceiverFlag") private void registerReceiver() { IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); - activity_.registerReceiver(this, filter); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + activity_.registerReceiver(this, filter, Context.RECEIVER_NOT_EXPORTED); + } else + activity_.registerReceiver(this, filter); + } else + activity_.registerReceiver(this, filter); } private void unregisterReceiver() {