Hi,
I had a problem for which there was no solution:
Somehow I managed to get a service to run in the "foreground" under Android 13 (API 33). What's interesting is that this service doesn't stop, even if I stop the application and the "start at boot" works. Of course it has the message that the running service is in the background, but the user can turn it off, so it is not confusing.
And with the timed receiver I can call this service and the http request works in the background.
Maybe I misunderstood something, but I took it to mean that foreground services can't really be used anymore, because they don't run in the "fixed" foreground anymore.
This is the code for my service:
I'm testing it now, but is it possible to use API 33 to use service ?
I had a problem for which there was no solution:
StartReceiverAt OkHttpUtils2 during phone sleep
Hi, I have a scheduled task that downloads a web page (OkHttpUtils2) every morning. When the phone is "not asleep" it can download it, otherwise it gets an error message: java.net.UnknownHostException: Unable to resolve host. StartReceiverAt(Reminder_receiver, nextTime, False) Public Sub...
www.b4x.com
Somehow I managed to get a service to run in the "foreground" under Android 13 (API 33). What's interesting is that this service doesn't stop, even if I stop the application and the "start at boot" works. Of course it has the message that the running service is in the background, but the user can turn it off, so it is not confusing.
And with the timed receiver I can call this service and the http request works in the background.
Maybe I misunderstood something, but I took it to mean that foreground services can't really be used anymore, because they don't run in the "fixed" foreground anymore.
Receivers and Services in 2023+
In the early days of Android services were simple to use and powerful. They allowed doing all kinds of things in the backgrounds with very few restrictions. That's not the case with newer versions of Android. With a few exceptions (that aren't 100% reliable), the only use case for services is to...
www.b4x.com
This is the code for my service:
MainService:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Service_Create
Dim notification As Notification
Log("=== Service Create")
notification.Initialize
notification.Initialize2(notification.IMPORTANCE_MIN)
notification.Icon = "icon"
notification.Light = False
notification.Vibrate = False
notification.Sound = False
'notification.OnGoingEvent = True
'notification.AutoCancel = False
notification.SetInfo(Application.LabelName, "Service running", Main)
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
Service.AutomaticForegroundNotification = notification
End Sub
Sub Service_Start (StartingIntent As Intent)
Log("=== Service Start")
'Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub
Sub Service_Destroy
Log("=== Service Destroy")
End Sub
Sub getData
Log("=== Service getData")
Private getGustoData As getHttpDataGusto
getGustoData.Initialize
getGustoData.startFromService = True
getGustoData.process
End Sub
I'm testing it now, but is it possible to use API 33 to use service ?