Android Question Notification with download: local or firebase?

voxel

Active Member
Licensed User
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.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Should I stop using a Receiver and use a Service?
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.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
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..
 
Upvote 0

voxel

Active Member
Licensed User
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.

Thank. I will try to put it to sleep before downloading.

To complete the behavior, when I wake up both smartphones (StartReceiverAt once a day at 12:00 PM) at 6:00 PM.
  • Samsung Galaxy A13 / Android 14: The notification is displayed with the time 12:30 PM, and the message "Download KO" appears.
  • Xiaomi Redmi A3 / Android 15: No notification. 3 minutes later, the notification appears with "Download OK."

The Receiver trigger behavior is significantly different between the two smartphones.
 
Upvote 0

voxel

Active Member
Licensed User
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


I'll try by calling a Service from the Receiver.
 
Upvote 0
Top