Android Question [Solved] Problems with notification, FindNextTime and SDK 31

asales

Expert
Licensed User
Longtime User
For several years I use this code in my apps to show a notification every day at the morning and night.

Now I created a new app - that requires SDK 31 in play store - and don't work anymore.
I get the error below (Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.).

I made this changes:
1 - Use StartServiceAtExact and add to manifest editor:
AddPermission(android.permission.SCHEDULE_EXACT_ALARM)

2 - Try to set the automatic foreground mode to NEVER:

3 - Update the core:
try the attached update - 11.81

No change worked.
This happens in device with Android 12 (in Android 10 works).

As I have dozens of apps (26) with this feature, change to a push notification is no produtive.

Thanks in advance for any tip to solve this issue.

B4X:
Caused by: java.lang.IllegalArgumentException: br.com.app.everyday: 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)
    ... 20 more
Time error: 12:40
br.com.app.everyday
nb6_vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv7 (java line: 175)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at br.com.app.everyday.nb6._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv7(nb6.java:175)
    at br.com.app.everyday.alarme$ResumableSub_Simple_NotificationNB6Txt.resume(alarme.java:382)
    at br.com.app.everyday.alarme._simple_notificationnb6txt(alarme.java:297)
    at br.com.app.everyday.alarme._service_start(alarme.java:232)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at br.com.app.everyday.alarme.handleStart(alarme.java:100)
    at br.com.app.everyday.alarme.access$000(alarme.java:8)
    at br.com.app.everyday.alarme$2.run(alarme.java:80)
    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:8663)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.IllegalArgumentException: br.com.app.everyday: 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)
    ... 20 more
 
Last edited:

agraham

Expert
Licensed User
Longtime User
See post #10 here for the solution

EDIT: I missed that you say you tried the updated core. In which case I am surprised that it hasn't fixed the problem. What is the code in service_start that causes the problem - so I can see what you are calling.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
What is the code in service_start that causes the problem - so I can see what you are calling.
Thanks for your answer.

I started to create a little project to you see the problem, but (as always happens) in this project the notification it worked :rolleyes:.

I'll do more tests and try to find what could be the problem.
 
Upvote 0
Top