I'm trying to show push notifications in Android 12 but I'm getting this error:
IllegalArgumentException Targeting S+ requires that one of FLAG_INMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
To show notifications I'm doing this:
val contentIntent = NavDeepLinkBuilder(this).apply{
setComponentName(MainActivity::class.java)
setGraph(R.navigation.nav_graph)
setDestination(R.id.dialog_custom)
setArguments(arguments)}.createPendingIntent()
val notification = NotificationCompat.Builder(this, channelId).apply{
setSmallIcon(R.drawable.ic_icon_notification)
setContentTitle(...)
setContentText(...)
setStyle(...)
setContentIntent(contentIntent)
setAutoCancel(true)}.build()
How can I fix this error? I tried to add PendingIntent.FLAG_IMMUTABLE in createPendingIntent() arguments but it's not possible. Any idea?
Edit: I'm using version 2.5.1 of Navigation library so, I should have this changes applied in my version https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0-alpha04
Edit 2:
This is the stacktrace:
Fatal Exception: java.lang.IllegalArgumentException: com.example.myapplication: 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:378)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:461)
at android.app.PendingIntent.getActivity(PendingIntent.java:447)
at android.app.PendingIntent.getActivity(PendingIntent.java:411)
at com.google.firebase.messaging.CommonNotificationBuilder.createContentIntent(com.google.firebase:firebase-messaging##20.3.0:125)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging##20.3.0:27)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging##20.3.0:9)
at com.google.firebase.messaging.DisplayNotification.handleNotification(com.google.firebase:firebase-messaging##20.3.0:27)
at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging##20.3.0:65)
at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging##20.3.0:44)
at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging##20.3.0:27)
at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging##20.3.0:17)
at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging##20.3.0:43)
at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(:6)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement##18.0.0:2)
at java.lang.Thread.run(Thread.java:920)
Related
I'm using createVoiceAppSearchIntent function from SearchView and this method still using PendingIntent.FLAG_ONE_SHOT and is crashing my app.
Causing 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.
There's something that I can do about?
Here is the log:
Fatal Exception: java.lang.IllegalArgumentException: 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:382)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465)
at android.app.PendingIntent.getActivity(PendingIntent.java:451)
at android.app.PendingIntent.getActivity(PendingIntent.java:415)
at androidx.appcompat.widget.SearchView.createVoiceAppSearchIntent(SearchView.java:1594)
at androidx.appcompat.widget.SearchView.onVoiceClicked(SearchView.java:1251)
at androidx.appcompat.widget.SearchView$5.onClick(SearchView.java:991)
at android.view.View.performClick(View.java:7792)
at android.view.View.performClickInternal(View.java:7769)
at android.view.View.access$3800(View.java:910)
at android.view.View$PerformClick.run(View.java:30218)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8669)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
This is due to update required for PendingIntent for apps targeting version 31 or above.
Try updating androidx.appcompat.widget
implementation "androidx.appcompat:appcompat:1.5.1"
Not sure what is the exact version that fixed this, but latest will do the work.
I had to update the sdk version from 30 to 31. I am getting error in Android 11, this is working fine in android 10. Please suggest me what is wrong.
E/AndroidRuntime: FATAL EXCEPTION: WorkManager-WorkManagerTaskExecutor-thread-0
Process: com.cpplusworld.ams, PID: 25796
java.lang.IllegalArgumentException: com.cpplusworld.ams: 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.
After updating targetsdk version to 31, the app is giving an error on pending intents. I have updated all the pending intents and then run the app. But the app is now crashing with this error
Caused by: java.lang.IllegalArgumentException: fm.iono.p953: 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.
But the line that the app crashes is the following:
val gmsTracker = GoogleAnalytics.getInstance(context).newTracker(gmsId)
see the screenshot below. I have highlighted the line with blue color where the app crashes. And from the logcat you can see the error. Not sure why the app is crashing on the line where no pending intent is available :)
Any help will be appreciated
Make sure you are on the latest version of the Google Analytics dependency. It apparently is setting up that PendingIntent, and only the developers of Google Analytics can change that behavior.
When I update my Xamarin Android head to compile using Android 12, and change the minimal version to 10.0 and the target to 12.0, I get the following exception when the application starts:
Java.Lang.IllegalArgumentException: '[Package Name]: 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.
The stacktrace is
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:196)
at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:128)
at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:93)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
Now my project contains no such PendingIntent so I am wondering what I should do.
In this case adding the Xamarin.AndroidX.Work.Runtime NuGet package did the trick. In general this exception could mean a dependent package is not updated to support this Android 12 requirement.
In our app we have dependency: com.huawei.hms:base:6.1.0.302 and use HuaweiApiAvailability class.
As result of calling this function PendingIntent getErrPendingIntent(Context var1, ConnectionResult var2) we have exception:
Process: com...preview, PID: 10355
java.lang.IllegalArgumentException: com...preview: 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:375)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
at android.app.PendingIntent.getActivity(PendingIntent.java:444)
at android.app.PendingIntent.getActivity(PendingIntent.java:408)
at com.huawei.hms.api.b.getErrPendingIntent(HuaweiApiAvailabilityImpl.java:10)
at com.huawei.hms.common.internal.BaseHmsClient.resolution(BaseHmsClient.java:3)
at com.huawei.hms.common.internal.BaseHmsClient.checkAvailabilityAndConnect(BaseHmsClient.java:34)
at com.huawei.hms.common.internal.BaseHmsClient.connect(BaseHmsClient.java:1)
at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.connect(HuaweiApiManager.java:21)
at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.sendRequest(HuaweiApiManager.java:24)
at com.huawei.hms.common.internal.HuaweiApiManager.connectAndSendRequest(HuaweiApiManager.java:8)
at com.huawei.hms.common.internal.HuaweiApiManager.handleMessage(HuaweiApiManager.java:7)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
Question: are you planning to update PendingIntens with new flag for Android 12?
Update
A new version of the base SDK has been released :
implementation 'com.huawei.hms:base:6.2.0.300'
This issue has been fixed, you can explicitly depend on this version of base sdk first, which should fix the problem.
Thank you for your feedback, the R&D team confirms that a fixed version will be released at the end of September.
Please use the latest version for testing by that time. Thanks.