Android 14 Api 34崩溃了
darkSuperman opened this issue · 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.
错误表明,从 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)
}
可以更新一下嘛?
I also have this issue please solve this ASAP.
Use PendingIntent.FLAG_IMMUTABLE
instead of custom PENDING_FLAG_IMMUTABLE
And also change this:
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.
@lolosssss even this is not helping. Any other solutions?
@darkSuperman are you able to find any solutions?