Android Question Notification with background app (SOLVED)

IdasI4A

Active Member
Licensed User
Longtime User
I am using NB6 to display notifications.
If the app is in the foreground when the notification arrives and I click on it, it takes me to the indicated page, but if the app is in the background when I click on the notification, it disappears and does not take me to the indicated page.
How can I make it so that when I click on the notification it shows me the app, whether it is active or not?

Thnks
 

IdasI4A

Active Member
Licensed User
Longtime User
I can't get it. I use B4XPages and what I do is:

When I make the notification
B4X:
    Dim N As NB6

    N.Initialize("default", Application.LabelName,"DEFAULT")
    N.AutoCancel(True)
    N.SmallIcon(LoadBitmap(File.DirAssets,"icon.png"))
    N.OldNotificationIcon("icon")
    N.OnGoing(True)
    N.Build(Texto,Titulo,"miTag" & Valor, Main ).Notify(1)

I have added in Main
B4X:
Sub Activity_Resume
    B4XPages.Delegate.Activity_Resume
    B4XPages.MainPage.ActivityResume ' <-- This line
End Sub

And in B4MainPage
B4X:
Public Sub ActivityResume
    Dim in As Intent = B4XPages.GetNativeParent(Me).GetStartingIntent
    If in.IsInitialized And in <> LastIntent Then
        LastIntent = in
        If in.HasExtra("Notification_Tag") Then
            Dim Tag As String = in.GetExtra("Notification_Tag")
            Dim Linea As Int
            
            B4XPages.ShowPage("Tramites")
            pgTramites.VerTramite(Tag)
            
        End If
    End If
End Sub
If the app is in the foreground when I click on the notification it shows me the page "Tramites", if it is in the background it does nothing.
 
Upvote 0

IdasI4A

Active Member
Licensed User
Longtime User
I generated the notification when I got a message from FireBase, the problem was in the message that already included a notification.
If the message is:
JSON:
notification {
    title=titulo,
    body=body of notification,
}
data {
    campo1=valor1,
    campo2=valor2,
}

When I receive the message with the app in the background it puts the message notification and when I click on it the app doesn't know about it.
But if the message is:

JSON:
data {
    campo1=valor1,
    campo2=valor2,
}

When I receive the message to the app creates the notification, when I click on the notification the app knows tanato this in foreground or background.
I comment it in case someone can help you.
Thanks
 
Upvote 0
Top