diff --git a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Enumerator.java b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Enumerator.java index 35193d3250..5036b430b8 100644 --- a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Enumerator.java +++ b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Enumerator.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.hardware.usb.UsbManager; +import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; @@ -64,9 +65,26 @@ public Enumerator(Context context, DeviceListener listener){ mListener = listener; mContext = context; - context.registerReceiver(mBroadcastReceiver, new IntentFilter(UsbUtilities.ACTION_USB_PERMISSION)); - context.registerReceiver(mBroadcastReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED)); - context.registerReceiver(mBroadcastReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED)); + // Extra flag to counteract the extra requirements to pass an exported or not-exported value + // when broadcasting for Android 12 and up. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + context.registerReceiver(mBroadcastReceiver, + new IntentFilter(UsbUtilities.ACTION_USB_PERMISSION), + Context.RECEIVER_EXPORTED); + + context.registerReceiver(mBroadcastReceiver, + new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED), + Context.RECEIVER_EXPORTED); + + context.registerReceiver(mBroadcastReceiver, + new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED), + Context.RECEIVER_EXPORTED); + } else { + // For pre-Android 12 versions, use the standard registerReceiver without the export flag + context.registerReceiver(mBroadcastReceiver, new IntentFilter(UsbUtilities.ACTION_USB_PERMISSION)); + context.registerReceiver(mBroadcastReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED)); + context.registerReceiver(mBroadcastReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED)); + } onDeviceAttach(context); }