jiangdongguo / AndroidUSBCamera

🔥🔥🔥Flexible and useful UVC camera engine on Android platform, supporting multi-road cameras!
https://juejin.cn/post/7115229806844706847
Apache License 2.0
2.33k stars 795 forks source link

Android 14 Api 34崩溃了 #667

Open darkSuperman opened 4 months ago

darkSuperman commented 4 months ago

java.lang.IllegalArgumentException:com.nextai.object: Targeting U+ (version 34 and above) disallows creating or retrieving a PendingIntent with FLAG_MUTABLE, an implicit Intent within and without FLAG_NO_CREATE and FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT for security reasons. To retrieve an already existing PendingIntent, use FLAG_NO_CREATE, however, to create a new PendingIntent with an implicit Intent use FLAG_IMMUTABLE.

查了一下: https://stackoverflow.com/questions/77275691/targeting-u-version-34-and-above-disallows-creating-or-retrieving-a-pendingin

错误表明,从 Android 14(API 34)开始,如果您在具有 FLAG_MUTABLE 的 PendingIntent 对象内有一个隐式意图,您的应用就会崩溃。

如果您不需要FLAG_MUTABLE标志,则只需将其更改为FLAG_IMMUTABLE。但是,如果您的应用需要可变意图,那么我建议采用以下解决方案之一: val implicitIntent = Intent("com.example.app.action.WHATEVER") val implicitPendingIntent = if (Build.VERSION.SDK_INT >= 34) { PendingIntent.getBroadcast(this, 0, implicitIntent, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT) } else { PendingIntent.getBroadcast(this, 0, implicitIntent, PendingIntent.FLAG_MUTABLE) }

可以更新一下嘛?

mahmoudramzy400 commented 4 months ago

I also have this issue please solve this ASAP.

lolosssss commented 4 months ago

https://github.com/jiangdongguo/AndroidUSBCamera/blob/ebfd9437eb6e23e30f583a0151474b2fa6267fca/libuvc/src/main/java/com/jiangdg/usb/USBMonitor.java#L181

Use PendingIntent.FLAG_IMMUTABLE instead of custom PENDING_FLAG_IMMUTABLE

And also change this: https://github.com/jiangdongguo/AndroidUSBCamera/blob/ebfd9437eb6e23e30f583a0151474b2fa6267fca/libuvc/src/main/java/com/jiangdg/usb/USBMonitor.java#L189

to:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    context.registerReceiver(mUsbReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
    context.registerReceiver(mUsbReceiver, filter);
}

Hope this help.

Utsav-Mehta commented 3 months ago

@lolosssss even this is not helping. Any other solutions?

Utsav-Mehta commented 3 months ago

@darkSuperman are you able to find any solutions?

xiaohua717 commented 2 months ago

@lolosssss even this is not helping. Any other solutions? Have you solved it yet?

Thejas775 commented 1 month ago

@lolosssss Any updates on this ?

xiaohua717 commented 1 month ago
Intent intent = new Intent(ACTION_USB_PERMISSION);
intent.setPackage(context.getPackageName()); // add it
mPermissionIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_MUTABLE);
final IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
 filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    context.registerReceiver(mUsbReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
  context.registerReceiver(mUsbReceiver, filter);
 }

work for Galaxy S23 , Android 14

Thejas775 commented 1 month ago

xiaohua717

Intent intent = new Intent(ACTION_USB_PERMISSION);
intent.setPackage(context.getPackageName()); // add it
mPermissionIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_MUTABLE);
final IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
 filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    context.registerReceiver(mUsbReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
  context.registerReceiver(mUsbReceiver, filter);
 }

work for Galaxy S23 , Android 14

Intent intent = new Intent(ACTION_USB_PERMISSION);
intent.setPackage(context.getPackageName()); // add it
mPermissionIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_MUTABLE);
final IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
 filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    context.registerReceiver(mUsbReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
  context.registerReceiver(mUsbReceiver, filter);
 }

work for Galaxy S23 , Android 14

Hi I edited the file but I'm unable to compile. Im a Newbie to java and other stuff. So can you please help me. Thanks

Thejas775 commented 1 month ago

https://github.com/jiangdongguo/AndroidUSBCamera/blob/ebfd9437eb6e23e30f583a0151474b2fa6267fca/libuvc/src/main/java/com/jiangdg/usb/USBMonitor.java#L181

Use PendingIntent.FLAG_IMMUTABLE instead of custom PENDING_FLAG_IMMUTABLE

And also change this:

https://github.com/jiangdongguo/AndroidUSBCamera/blob/ebfd9437eb6e23e30f583a0151474b2fa6267fca/libuvc/src/main/java/com/jiangdg/usb/USBMonitor.java#L189

to:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
  context.registerReceiver(mUsbReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
  context.registerReceiver(mUsbReceiver, filter);
}

Hope this help.

@jiangdongguo please check on this. \