AndroidUSBCamera icon indicating copy to clipboard operation
AndroidUSBCamera copied to clipboard

Android 14 Api 34崩溃了

Open darkSuperman opened this issue 8 months ago • 9 comments

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) }

可以更新一下嘛?

darkSuperman avatar Jun 01 '24 08:06 darkSuperman