Android Question errors on sdk 31 - b4A ver 12 - Unable to start receiver

alon

Active Member
Licensed User
Longtime User
Hi ,

Since upgrading to sdk 31 I am having a few problems and the app crash.

I read all the posts about the new sdk problems.

And I did the following:

I start using StartServiceAtExact

add to manifest: <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>

add Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER to the Service_Create (of the firebase service)



B4X:
Sub Service_Create



fm.Initialize("fm")

Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER '05-12-2022



End Sub



But still have problems.

I am using B4A ver 12



Error Log:





B4X:
12-06 10:22:14.334  5433  5433 I B4A     : ~i:** Receiver (firebasemessaging) OnReceive **
12-06 10:22:14.339  5433  5433 D AndroidRuntime: Shutting down VM
12-06 10:22:14.340  5433  5433 E AndroidRuntime: FATAL EXCEPTION: main
12-06 10:22:14.340  5433  5433 E AndroidRuntime: Process: bina.YomanTech, PID: 5433
12-06 10:22:14.340  5433  5433 E AndroidRuntime: java.lang.RuntimeException: Unable to start receiver bina.YomanTech.firebasemessaging$firebasemessaging_BR: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service bina.YomanTech/.firebasemessaging
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.ActivityThread.handleReceiver(ActivityThread.java:4770)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.ActivityThread.access$1800(ActivityThread.java:310)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2292)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:106)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.os.Looper.loopOnce(Looper.java:226)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.os.Looper.loop(Looper.java:313)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:8669)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
12-06 10:22:14.340  5433  5433 E AndroidRuntime: Caused by: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service bina.YomanTech/.firebasemessaging
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.os.Parcel.readParcelable(Parcel.java:3345)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.os.Parcel.createExceptionOrNull(Parcel.java:2432)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.os.Parcel.createException(Parcel.java:2421)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.os.Parcel.readException(Parcel.java:2404)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.os.Parcel.readException(Parcel.java:2346)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:6968)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1927)
12-06 10:22:14.340  5
433  5433 E AndroidRuntime:     at android.app.ContextImpl.startForegroundService(ContextImpl.java:1893)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:798)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:798)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.startServiceFromReceiver(ServiceHelper.java:141)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at bina.YomanTech.firebasemessaging$firebasemessaging_BR.onReceive(firebasemessaging.java:17)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.ActivityThread.handleReceiver(ActivityThread.java:4761)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     ... 9 more
12-06 10:22:14.340  5433  5433 E AndroidRuntime: Caused by: android.os.RemoteException: Remote stack trace:
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:771)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:679)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at com.android.server.am.ActivityManagerService.startService(ActivityManagerService.java:14099)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2960)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:     at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3036)
12-06 10:22:14.340  5433  5433 E AndroidRuntime:
 

alon

Active Member
Licensed User
Longtime User
You must sent messages with high priority. Use the updated B4J code to send the messages.
Hi Erel,

Thanks for you help.

But I am not sure I understand.

I am sending the messages with http request from sql server of my client.



If you mean that I should pop up the messages with high priority from b4a, then I will try to send it like this:

B4X:
Dim n As Notification

n.Initialize2(n.IMPORTANCE_HIGH) 

n.Vibrate = True

n.Icon = "notifyicon"

n.AutoCancel = True



Can you please show me how to send from updated B4J.



Thanks In Advance
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Can you please show me how to send from updated B4J.
See the download here and use the code in the download
 
Upvote 0

alon

Active Member
Licensed User
Longtime User
See the download here and use the code in the download
Hi Erel,
According to your answer and the b4j code,
I understand that your first answer was that I should post the message with "priority" : 10 .

Am I correct?
 
Upvote 0
Top