应用程序在运行时崩溃并出现以下错误:
java.lang.IllegalArgumentException:maa.abc:定位 S+(版本 31 及更高版本)要求 FLAG_IMMUTABLE 或 FLAG_MUTABLE 在创建 PendingIntent 时指定。 强烈考虑使用 FLAG_IMMUTABLE,仅当某些功能依赖于 PendingIntent 可变时才使用 FLAG_MUTABLE,例如如果 它需要与内联回复或气泡一起使用。 在 android.app.PendingIntent.checkFlags(PendingIntent.java:375) 在 android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645) 在 android.app.PendingIntent.getBroadcast(PendingIntent.java:632) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager.createBroadcastIntent(PlayerNotificationManager.java:1373) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager.createPlaybackActions(PlayerNotificationManager.java:1329) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager。(PlayerNotificationManager.java:643) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager。(PlayerNotificationManager.java:529) 在com.google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:456) 在com.google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:417)
我尝试了所有可用的解决方案,但该应用程序在 Android 12 上仍然崩溃。
@Nullable
@Override
public PendingIntent createCurrentContentIntent(@NonNull Player player) {
Intent intent = new Intent(service, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(service, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}
如果使用java或react-native,则将其粘贴到app/build.gradle中
dependencies {
// ...
implementation 'androidx.work:work-runtime:2.7.1'
}
如果使用 Kotlin 那么使用这个
dependencies {
// ...
implementation 'androidx.work:work-runtime-ktx:2.7.0'
}
如果有人仍然面临 Android 12 的崩溃问题,请确保在 AndroidMenifest.xml 中添加以下内容
<activity
...
android:exported="true" // in most cases it is true but based on requirements it can be false also
>
// If using react-native push notifications then make sure to add into it also
<receiver
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver" android:exported="true">
// Similarly
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="true">
检查并更新exoplayer的依赖版本到最新版本
android.app.PendingIntent.getBroadcast()
之前用于返回
@Nullable
@Override
private static PendingIntent createBroadcastIntent(
String action, Context context, int instanceId) {
Intent intent = new Intent(action).setPackage(context.getPackageName());
intent.putExtra(EXTRA_INSTANCE_ID, instanceId);
return PendingIntent.getBroadcast(
context, instanceId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
如果你仔细观察,上面的代码片段中缺少 PendingIntent.FLAG_IMMUTABLE
现已更新以返回以下内容
@Nullable
@Override
private static PendingIntent createBroadcastIntent(
String action, Context context, int instanceId) {
Intent intent = new Intent(action).setPackage(context.getPackageName());
intent.putExtra(EXTRA_INSTANCE_ID, instanceId);
int pendingFlags;
if (Util.SDK_INT >= 23) {
pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
} else {
pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT;
}
return PendingIntent.getBroadcast(context, instanceId, intent, pendingFlags);
}
就我而言,使用前台交付系统读取标签,它的工作原理..
如果您让应用程序在 Android 12 中运行,请使用以下命令:
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(this,
0, new Intent(this, getClass()).addFlags(
Intent.FLAG_ACTIVITY_SINGLE_TOP),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(this,
0, new Intent(this, getClass()).addFlags(
Intent.FLAG_ACTIVITY_SINGLE_TOP),
PendingIntent.FLAG_UPDATE_CURRENT);
}
Kotlin 的解决方案,如果您使用 API M,只需添加此标志
val flags = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE
else -> FLAG_UPDATE_CURRENT
}
val toastPendingIntent = PendingIntent.getBroadcast(context, 0, providerIntent, flags)
通过添加 app/build.gradle 来修复
dependencies {
// ...
implementation 'androidx.work:work-runtime-ktx:2.7.0'
}
供日后参考
将
implementation 'androidx.work:work-runtime:2.7.1
添加到 app/build.gradle
dependencies {
// ...
implementation 'androidx.work:work-runtime:2.7.1'
}
将
| PendingIntent.FLAG_IMMUTABLE
添加到定义 PendingIntent 的行
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, configIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
我面临同样的问题,按照大多数答案中的指示,我已更新我的依赖项,如下所示。
dependencies {
/* Use either Kotlin or Java dependency as per your project */
// ...
/* Android Arch Component Work Manager for Kotlin */
implementation 'androidx.work:work-runtime-ktx:2.7.0'
//...
/* Android Arch Component Work Manager for Java */
def work_version = "2.7.1"
implementation "androidx.work:work-runtime:$work_version"
// optional - Test helpers
androidTestImplementation "androidx.work:work-testing:$work_version"
}
但是仅添加上述内容并没有解决我的问题,应用程序仍然崩溃了。
所以我关掉了 Android Lint: Missing Pending Intent Mutability,找到下面的步骤来关掉。
关闭挂起的意图可变性
转到“搜索”选项并搜索“PendingIntent”,您将收到如下所示的窗口。
Android Lint 的切换:缺少挂起的意图可变性,您就可以开始了。
我在 Android 12 上的 Url_Launcher 上遇到了同样的问题。将其添加到
build.gradle
文件后,我解决了我的问题。
dependencies {
// ...
implementation 'androidx.work:work-runtime-ktx:2.7.0'
}
我通过在 ...android/app/build.gradle 中添加以下内容解决了这个问题
implementation 'androidx.work:work-runtime-ktx:2.8.0-alpha01'
https://github.com/react-native-maps/react-native-maps/issues/4083#issue-1119280606
如果Chuck库产生了您的问题,则更新SDK版本后您将无法使用它。您可以轻松地将其替换为 Chucker(Chuck 的叉子):https://github.com/jgilfelt/chuck/issues/101#issuecomment-869119599。
有几件事,请确保您使用的是 JDK 11,然后删除 android 文件夹中的 .gradle 文件夹,然后按照这个精彩的答案进行操作SO答案。
执行 gradle clean 后尝试