I implemented a Receiver with a quick download and then a notification displayed once a day at 12 p.m.
The alarm works fine, but I get an HTTP connection error since the smartphone is in standby mode. The notification does display a connection error.
Is there a way to "wake up" the smartphone to maintain the HTTP connection?
Do I need to launch the Receiver more often to have a chance of the smartphone not going to sleep?
Should I stop using a Receiver and use a Service?
I'm really wondering if I should use notifications with Firebase instead; it seems more reliable to me (and perhaps simpler when I port this feature to B4i).
Have you ever faced this problem? This choice?
Thank you for your advice.
What you can do is start a service from the receiver and set the service "foreground type" to shortService.
However, you should first make some tests with the receiver. If the phone wakes up then it will not immediately have an internet connection. Sleep for a few seconds and try again.
I don't know if it could be of any help here, but have a quick look at this thread.
I had the same "Internet not available" problem after a boot/reboot, altough it was in an home widget.
Eventually it could be of inspiration..
What you can do is start a service from the receiver and set the service "foreground type" to shortService.
However, you should first make some tests with the receiver. If the phone wakes up then it will not immediately have an internet connection. Sleep for a few seconds and try again.
I just tried by pausing for 15 seconds before downloading. The download works 1 out of 2 times, it's unstable.
B4X:
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
Sleep(15000)
Dim telecharge As HttpJob
telecharge.Initialize("",Me)
telecharge.Download(urlidbdd)
Wait For (telecharge) JobDone(telecharge As HttpJob)
If telecharge.Success Then