Need one help. I have an app with FCM Push Notification, and everything was working until Android 12. Now can't getting notifications on Android 12+ devices. Getting this error when I am setting the targetSdkVersion to 31 or more.
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.at android.app.PendingIntent.checkFlags(PendingIntent.java:401)at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:671)at android.app.PendingIntent.getBroadcast(PendingIntent.java:658)at com.google.firebase.iid.zzl.zzd(Unknown Source:18)at com.google.firebase.iid.zzl.zzb(Unknown Source:230)at com.google.firebase.iid.zzl.zza(Unknown Source:0)at com.google.firebase.iid.zzj.zzb(Unknown Source:42)at com.google.firebase.iid.zzj.getToken(Unknown Source:58)at com.google.firebase.iid.FirebaseInstanceId.getToken(Unknown Source:10)at com.google.firebase.iid.FirebaseInstanceId.zzcfy(Unknown Source:4)at com.google.firebase.iid.FirebaseInstanceIdService.zza(Unknown Source:156)at com.google.firebase.iid.FirebaseInstanceIdService.handleIntent(Unknown Source:303)at com.google.firebase.iid.zzc.run(Unknown Source:4)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)at java.lang.Thread.run(Thread.java:1012)
Getting this error. Please help.
Notifications don't work when the targetSDKVersion is set to 31. But 30 works. But using 30 we won't be able to upload the app in the Play Store.
//build.gradle(Module)
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 33
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.rmf.simplysave"
minSdkVersion 19
targetSdkVersion 31
multiDexEnabled true
}
}
implementation 'com.google.android.gms:play-services:11.4.2'
implementation 'com.google.code.gson:gson:2.8.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.firebase:firebase-messaging:11.4.2'
implementation 'com.google.firebase:firebase-core:11.4.2'
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
sendRegistrationToServer(refreshedToken);
@Override
public void onComplete(String s, Object o) {
Log.e("On Complete",s);
}
});
}
//build.gradle(Project)
dependencies {
classpath 'com.android.tools.build:gradle:3.4.3'
//classpath 'com.appdynamics:appdynamics-gradle-plugin:5.3.1565'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:3.2.0'
}