如果您让您的应用在 android 12 中运行,则会有一个新的 PendingIntent 可变性标志。如果您不希望 PendingIntent 被静音,请使用
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
如果您希望 PendingIntent 静音,请使用以下命令:
PendingIntent pendingIntent;
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
在 Google 文档中说,强烈考虑使用 FLAG_IMMUTABLE,仅在某些功能依赖于 PendingIntent 可变的情况下才使用 FLAG_MUTABLE。改变应该是直截了当的。
此外,如果您在应用中使用 AdMob 20.4.0 或更低版本,请确保添加以下工作管理器依赖项:
//Work Manager dependency
implementation 'androidx.work:work-runtime:2.7.1'
请注意,当前工作管理器依赖版本是 2.7.1。如果需要,您可以将版本更新到最新版本。