Hello,
I'm trying to set up a local notification to be triggered in the background every 30 seconds. It works when the app is in the foreground, but when it's in the background, I get this error.
Thanks for your help.
Is there a link to some sample code? (I couldn't find it on the forum.)
Error : java.lang.RuntimeException: Unable to start service fr.lyzo.servicenotification@ae239d9 with Intent { cmp=fr.lyzo/.servicenotification (has extras) }: java.lang.RuntimeException: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{936f40 30919:fr.lyzo/u0a248} targetSDK=36
I'm trying to set up a local notification to be triggered in the background every 30 seconds. It works when the app is in the foreground, but when it's in the background, I get this error.
Thanks for your help.
Is there a link to some sample code? (I couldn't find it on the forum.)
Error : java.lang.RuntimeException: Unable to start service fr.lyzo.servicenotification@ae239d9 with Intent { cmp=fr.lyzo/.servicenotification (has extras) }: java.lang.RuntimeException: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{936f40 30919:fr.lyzo/u0a248} targetSDK=36
Manifest:
AddPermission(android.permission.POST_NOTIFICATIONS)
AddPermission(android.permission.WAKE_LOCK)
AddPermission(android.permission.SCHEDULE_EXACT_ALARM)
AddPermission(android.permission.USE_EXACT_ALARM)
AddPermission(android.permission.FOREGROUND_SERVICE)
AddPermission(android.permission.FOREGROUND_SERVICE_DATA_SYNC)
AddPermission(android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
Service:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private n As Notification
End Sub
Sub Service_Create
Dim n As Notification
n.Initialize2(n.IMPORTANCE_LOW)
End Sub
Sub Service_Start (StartingIntent As Intent)
Log("Service démarré")
n.Initialize
n.Icon = "icon"
n.SetInfo("Titre de la notification", "Ceci est le texte de la notification.", Main)
n.Notify(1) 'ID de notification
End Sub
Sub Service_Destroy
Log("Service arrêté")
Main:
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
'Pour éviter que le système tue votre service
Dim in As Intent
in.Initialize("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS", _
"package:" & Application.PackageName)
Try
StartActivity(in)
Catch
Log("Impossible d'ouvrir les paramètres d'optimisation batterie")
End Try
StartServiceAt(ServiceNotification, DateTime.Now + 30 * 1000, True)
End If
Last edited: