Android Question FirebaseMessaging with image download

dibesw

Active Member
Licensed User
Longtime User
I use FirebaseMessaging migrated to new platform (B4a 12.80).

I have need to issue a notify and at the same time DownloadAndSaveJPG (200kb).
To acquire the picture I have to wait for the download to finish
My phone is in doze mode (Xiaomi note pro 12)
and after few minutes Wait For (j) JobDone(j As HttpJob) It does not work anymore (BigPicture_Notification is no longer performed) and I and I have need to reopen and close the app for it to work.
If I uncomment Sleep(2000) this doesn't work, however it is not downloaded and it shows me the previously downloaded one.

Why does this happen?
Could it be that the download doesn't work in the receiver module?

(I tried sending the image in base64 but the message was too long)



FirebaseMessaging Receiver module:
Sub fm_MessageArrived (Message As RemoteMessage)
    provider.Initialize
    DownloadAndSaveJPG("https://www.xxxxxxxxxxxx.net/notifichestudio/" & Main.manager.GetString("utente") & "/dentista4.png")
    testotitle=Message.GetData.Get("title")
    testobody=Message.GetData.Get("body")
    testonote=Message.GetData.Get("notedomani")
    appoimage=Message.GetData.Get("image")
    ToastMessageShow(Message.GetData.Get("image"),False)

    'Sleep(2000)
    'Spostato in jobdone
    'BigPicture_Notification
End Sub

Sub BigPicture_Notification
    Dim n As NB6
    smiley = LoadBitmapResize(File.DirAssets, "smiley2.png", 24dip, 24dip, False)
    n.Initialize("custom sound", Application.LabelName, "DEFAULT").SmallIcon(smiley)
 
    Dim FileName As String = "tada.mp3"
    File.Copy(File.DirAssets, FileName, provider.SharedFolder, FileName)
    Dim in As Intent
    in.Initialize(in.ACTION_VIEW, "")
    provider.SetFileUriAsIntentData(in, FileName)
    n.SmallIcon(LoadBitmapResize(File.DirAssets, "smiley.png", 32dip, 32dip, True))
    'disable the default sound
    n.SetDefaults(False, True, True)
    'set custom sound
    n.CustomSound(provider.GetFileUri(FileName))
 
    Dim b As Bitmap = LoadBitmap(File.DirInternal, "dentista4.png")
    n.BigPictureStyle(b.Resize(256dip, 256dip, True), b, testotitle, testobody)
    n.Color(0xFF00AEFF)
    n.AddButtonAction(smiley, "Note di domani", MyReceiver2, "note")
 
    Dim cs As CSBuilder
    n.AddButtonAction(smiley, cs.Initialize.Color(Colors.Red).Bold.Append("Altre informazioni...").PopAll, MyReceiver2, "altro")

    Dim Notification As Notification = n.Build(testotitle, testobody, "tag", Main)
    Notification.Notify(3)
End Sub
Sub DownloadAndSaveJPG (Link2 As String)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Link2)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim out As OutputStream = File.OpenOutput(File.DirInternal, "dentista4.png", False)
        File.Copy2(j.GetInputStream, out)
        out.Close '<------ very important
        ProgressDialogHide
        'ToastMessageShow("DOWNLOAD",True)
        BigPicture_Notification
    End If
    j.Release
End Sub
 
Last edited:

asales

Expert
Licensed User
Longtime User
Check this example:
1704218015411.png
 

Attachments

  • PushExample.zip
    12.3 KB · Views: 48
Upvote 0

asales

Expert
Licensed User
Longtime User
Just for information:
I don't used the example for the last days and sent a push notification.
The device was in stand by for almost a day.
The firebase message was received and the notification was show fine.

Did you tried in another device?
 
Upvote 0
Top