Android Question Widget in targetSdkVersion="31"

davfla

Member
Licensed User
Longtime User
Hi all,

I've been trying for days now and can't get any further.

Since the forced update to Android Target API 31 in the Playstore, I get the following error message on devices with Android >= 12 when adding or remove the widget to/from the homescreen :
java.lang.RuntimeException: Unable to start receiver anywheresoftware.b4a.samples.homewidgets.widgetservice$widgetservice_BR: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service anywheresoftware.b4a.samples.homewidgets/.widgetservice
2022-11-01 20_05_15-HomeWidgets - B4A.png
After the error comes, the app takes about 2 minutes when you want to open it again. Sometimes Crash Window from Android also comes. The error is reproducible.

This also applies to Erel's example, which should serve as a guide to creating a widget.
2022-11-01 20_04_33-Android Emulator - Tablet_API_31_5558.png

I did not change anything in the example except the target version in the manifest. Then in this example the error comes as well.
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="31" />

What I have already tried :
- B4A 12.00 Beta included Core 11.81 with Android-33
- All possible variants with Service.AutomaticForegroundMode including removing the function and Service.StopAutomaticForeground in all variants.
- Android API 30 = No problem, Android API 31 = Failure, API 33 = Failure
- The problem is also in the live version of my app according to Google Play Console and not only with emulator devices.

What I also wonder why apparently no one else has this problem ? I have not found another thread about it. Am I perhaps doing something wrong ?
 

davfla

Member
Licensed User
Longtime User
Hi Erel,

thank you very much for your answer. Unfortunately, I can not see any change. It does not solve the problem.
- All possible variants with Service.AutomaticForegroundMode including removing the function and Service.StopAutomaticForeground in all variants.

I had attached the example.

David
 

Attachments

  • HomeWidgets.rar
    402 KB · Views: 34
Upvote 0

agraham

Expert
Licensed User
Longtime User
My God! This is so frustrating. Microsoft manages decades of backwards compatibility but Google just breaks s??t with each release. I really wish there was a viable mobile platform other than Android (and no it's not Apple).
 
Upvote 0

davfla

Member
Licensed User
Longtime User
I'm glad you see the error now too. I already wanted to make a video :) Then I'm now waiting to see if you find a solution and also search.

@agraham : I think in hell is extra a place for such developers at Google who make such nonsense.
 
Upvote 0

ilpesce

Member
Licensed User
Longtime User
add this permission
 
Upvote 0

davfla

Member
Licensed User
Longtime User
Hello ilpesce,

thank you for the suggestion. Unfortunately, this does not solve our problem when the widget is removed again. I have created a video here, which should show what exactly I mean. Included your suggestion.


However, the error probably does not occur only when the widget is removed. The many crashes of my live app speak for this.
So I am very grateful for your suggestion and would like to try other opinions about it.

David
 
Upvote 0

ilpesce

Member
Licensed User
Longtime User
Hello
I understand, my application gave a similar error only to the first widget inserted after installation then the following were ok.
I solved this by entering the aforementioned permission.
I recommend that you use a real device for testing.
every year it gets worse and worse ...:)
 
Upvote 0

davfla

Member
Licensed User
Longtime User
Hello ilpesce,

unfortunately I can not confirm this. I have now tried it on a real Device Samsung Galaxy A52s with Android 12. Installed via the B4A Bridge and read out with #Bridgelogger: True. And the result is exactly the same.
Edit : Permission was used.

Logger verbunden mit: samsung SM-A528B
--------- beginning of main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (main) Resume **
Permission: true
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Receiver (widgetservice) OnReceive **
*** Service (widgetservice) Create ***
** Service (widgetservice) Start **
Service started in foreground mode.
** Receiver (widgetservice) OnReceive **
** Service (widgetservice) Start **
Service started in foreground mode.
** Service (widgetservice) Destroy **
android.app.ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{c17baf2 u0 anywheresoftware.b4a.samples.homewidgets/.widgetservice}
at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2147)
at android.app.ActivityThread.access$2800(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2376)
at android.os.Handler.dispatchMessage(Handler.java:106)
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(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Fortunately, only an "internal" error message is thrown and the user does not notice anything.

The problem is that this error is transmitted to Google. In the future, Google plans to display the performance statistics in the Playstore with how the app works with the respective device. And that will look disastrous with a B4A widget usage with this error. Here is an example how it can look :)

1667669440106.png


1667669739979.png

>750 crashes ( ~150 users from ~8000) in 15 days is a hefty amount :)

But thanks for your suggestion.

David
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
In the future, Google plans to display the performance statistics in the Playstore

The Play Store will start applying store listing warnings on November 30, 2022.
Also apps will get lower visibility on store and will be excluded from trending categories.

Full text:
 
Upvote 0

PJLPJLPJL

Member
I hope this is helpful. I had some very similar problems after updating my widget program to TargetSDK 31 and added the permission mentioned above without improving things. However, when I uninstalled and reistalled my app it all worked perfectly.
 
Upvote 0
Top