当我将目标SDK更新到30+ (Android R或更高版本)时,我的PendingIntent上出现了一个lint警告Missing PendingIntent可变性标志。当我想定义PendingIntent时,FLAG_UPDATE_CURRENT标志。
我应该如何处理这个绒线没有对应用程序功能的影响?
当我将目标SDK更新到30+ (Android R或更高版本)时,我的PendingIntent上出现了一个lint警告Missing PendingIntent可变性标志。当我想定义PendingIntent时,FLAG_UPDATE_CURRENT标志。
我应该如何处理这个绒线没有对应用程序功能的影响?
当前回答
这是Work库的问题。 即使是最新版本也受到2.7.0-alpha04的影响
https://issuetracker.google.com/issues/194108978
作为临时解决方案-在gradle中注释掉包含“work”依赖项,并在整个项目中删除使用该类。至少这样你可以正常运行应用程序,并在其他功能和领域工作....
其他回答
如果你使用Java和ADMOB,你会在SDK S或Android 12上遇到PendingIntent错误。这里有一个修复,使ADMOB使用正确的工作-运行时。
implementation 'com.google.android.gms:play-services-ads:19.5.0'
constraints {
implementation('androidx.work:work-runtime:2.7.0-alpha05') {
because 'previous versions have a bug impacting this application'
}
}
我将我的work-runtime-ktx版本更新到2.7.1
在上面的修改之后,我又遇到了另一个错误
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type: ErrorScope{Error scope for class <ERROR CLASS> with arguments: org.jetbrains.kotlin.types.IndexedParametersSubstitution@14ac19e7}
看看我是如何通过更新kotlin-gradle-plugin版本来解决上述错误的。
实现androidx.work:work-runtime:2.7.1
我想分享一下我的病例。我把标志改为FLAG_IMMUTABLE,但只有当应用程序在后台时才会出现错误。我从这里解决了:https://github.com/firebase/firebase-android-sdk/issues/3115
根本原因是因为我以不赞成的方式检索FCM令牌:
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(activity, new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
String newToken = instanceIdResult.getToken();
}
});
然后更新依赖项:
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(task -> {
String newToken = task.getResult();
});
在我的项目中,这条线是可行的
PendingIntent = PendingIntent。getActivity(this,0, notificationIntent, PendingIntent。| PendingIntent.FLAG_IMMUTABLE;