For several years I use this code in my apps to show a notification every day at the morning and night.
www.b4x.com
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)
www.b4x.com
2 - Try to set the automatic foreground mode to NEVER:
www.b4x.com
3 - Update the core:
try the attached update - 11.81
www.b4x.com
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] Calculating the next scheduled time
Name: Find the next scheduled time. Description by example: You need to start a service each day at 5 am, 6:30 am and 8 pm. You need to find the ticks values of the next scheduled time, either today or tomorrow if it is after 8pm. Dim t As Long = FindNextTime(Array As Double(5, 6.5, 20))...

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)
android.jar / targetSdkVersion / minSdkVersion
There are several versioned components that affect the compilation process and the runtime behavior of our apps. The purpose of this tutorial is to explain the differences between them and help you choose which version to use. Each Android version is mapped to an api level. You can see this...

2 - Try to set the automatic foreground mode to NEVER:
[ SOLVED] Target SDK 31 widget crash
Hello, I am upgrading a widget-enabled app to targetSDK 31. When I install the widget, it does not load and I get an error. java.lang.RuntimeException: Unable to start receiver com.tempusumbra.solarwidget.solarw4x2$solarw4x2_BR: android.app.ForegroundServiceStartNotAllowedException...

3 - Update the core:
try the attached update - 11.81
[ SOLVED] Target SDK 31 widget crash
Hello, I am upgrading a widget-enabled app to targetSDK 31. When I install the widget, it does not load and I get an error. java.lang.RuntimeException: Unable to start receiver com.tempusumbra.solarwidget.solarw4x2$solarw4x2_BR: android.app.ForegroundServiceStartNotAllowedException...

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: