Android Question Download problem - service with Android 14

voxel

Member
Licensed User
Hello,
I have a problem with smartphones under Android 14 for downloading. I have never had a problem before (Android 13 or lower - since 2020).
I use the Downloadservice and HttpUtils2service classes.
When I launch the application for the first time (and it remains in the background), the download works well. But if I exit the application, the download no longer takes place, it remains pending.

In the log, I have this message:
sending message to waiting queue (CallSubDelayed - StartDownload)


B4X:
Private Sub stat_Click

    Dim ff As DownloadData

    ff.url = "https://exemple/..."
    ff.EventName = "ff"
    ff.Target = Me

    CallSubDelayed2(DownloadService, "StartDownload", ff)
    Wait For ff_fin
    
    'si téléchargement est OK
    If download=True Then
    ....
    
End Sub
    

Sub ff_Complete(Job As HttpJob)
    
    If Job.Success Then
        Dim out As OutputStream = File.OpenOutput(File.DirInternal, "api.csv", False)
        File.Copy2(Job.GetInputStream, out)
        out.Close
        download=True
        Job.Release
        CallSubDelayed(Me,"ff_fin")
    Else
        download=False
        Job.Release
        CallSubDelayed(Me,"ff_fin")
    End If
    
End Sub

Thank you for your help.
 

Alex_197

Well-Known Member
Licensed User
Longtime User
 
Upvote 0

voxel

Member
Licensed User
Hello,
Thanks for this link. My app is not in B4X, I had already updated with android 14 and added in the manifest:

AddPermission(android.permission.FOREGROUND_SERVICE_DATA_SYNC)
SetServiceAttribute(DownloadService, android:foregroundServiceType, "dataSync")
SetServiceAttribute(HttpUtils2Service, android:foregroundServiceType, "dataSync").


Why when I first launch the app, everything works fine and if I restart the app, the downloads no longer work? Is there an object on the services to reset when opening or closing the app?

I don't understand everything about this link. What is the simplest solution?
- Currently, I am downloading in the background, should I download in the foreground (without service) using the httpjob class directly?
- Switch my project to B4X? :-(
- Can this method be a solution? how to use it?

Private Sub Service_Timeout(Params As Map)
Service.StopForeground(NotificationId)
End Sub

Thanks for your help.
 
Last edited:
Upvote 0

voxel

Member
Licensed User
How large is the file that you are downloading?

If it is not huge then use the regular OkHttpUtils2 library and make the download from the starter service (for B4XPages projects this is not needed).


Hello, Thanks for your answer.
I download 1 file of 15MB when starting the app and then there are other times when I download a few Kilo bytes.
I will follow your advice by using the OkHttpUtils2 library instead of Services.
On my app on B4i, I already use OkHttpUtils2 library.
 
Upvote 0
Top