Hi,
I've coded a foreground service. It works fine with StartServiceAt with notification (wake-up once a day).
The problem is starting it after a smartphone reboot.
I get this error:
java.lang.RuntimeException: android.app.ForegroundServiceStartNotAllowedException: FGS type dataSync not allowed to start from BOOT_COMPLETED!
So I have in the Create of the service :
I now have this error on Service_Destroy (and crash) :
I'm not sure I'm on the right track, thank you for your help.
I just want my once-daily scheduling service to work when I restart my phone.
Manifest :
I've coded a foreground service. It works fine with StartServiceAt with notification (wake-up once a day).
The problem is starting it after a smartphone reboot.
I get this error:
java.lang.RuntimeException: android.app.ForegroundServiceStartNotAllowedException: FGS type dataSync not allowed to start from BOOT_COMPLETED!
So I have in the Create of the service :
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Service_Create
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
End Sub
Sub Service_Start (StartingIntent As Intent)
Log("Service démarré")
If StartingIntent.IsInitialized And StartingIntent.Action = "android.intent.action.BOOT_COMPLETED" Then
Dim n As Notification
n.Initialize
n.Icon = "icon_notif"
n.AutoCancel = True
n.SetInfo2("Lyzo","Analyse","",Main)
n.Notify(1)
Service.StartForeground(1,n)
ScheduleNextDownload
Service.StopAutomaticForeground
I now have this error on Service_Destroy (and crash) :
B4X:
--------- beginning of main
** Receiver (servicenotification) OnReceive **
*** Service (starter) Create ***
** Service (starter) Start **
** Service (servicenotification) Create **
Service crée
** Service (servicenotification) Start **
Service started in foreground mode.
Service démarré
Redémarrage détecté : on planifie ServiceNotification
Initialise StartServiceAt
Prochain téléchargement planifié pour : 08/18/2025-12:00:00
** Service (servicenotification) Destroy **
Service arrêté
android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{b2d92c2 u0 fr.lyzo/.servicenotification c:fr.lyzo}
at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2313)
at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2281)
at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2599)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8756)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:601)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:962)
I'm not sure I'm on the right track, thank you for your help.
I just want my once-daily scheduling service to work when I restart my phone.
Manifest :
B4X:
SetServiceAttribute(ServiceNotification, android:foregroundServiceType, dataSync)
AddPermission(android.permission.POST_NOTIFICATIONS)
AddPermission(android.permission.FOREGROUND_SERVICE)
AddPermission(android.permission.RECEIVE_BOOT_COMPLETED)
Last edited: