Android Question Notify with msgbox or simil

netsistemas

Active Member
Licensed User
Longtime User
I use FirebaseMessaging for recibe message in app

when main opens, the user loses the window they are in. I think I cannot launch a MSGBOX from the FIREBASENOTIFY service


B4X:
Sub NotificacionLocal(Title As String, Body As String, Tipo As String )
    Dim  NewNotificacion As NB6
Dim IdNotificacion As Int
    Private smiley As Bitmap
    
    
    Try

        Log("NotificacionLocal a")
        smiley = LoadBitmapResize(File.DirAssets, "f.ico", 24dip, 24dip, False)
        'DEFAULT - PRIORITY
        NewNotificacion.Initialize( "default",  Application.LabelName, "HIGH").SmallIcon(smiley)
        IdNotificacion = 10
        NewNotificacion.AddButtonAction(smiley, Tipo & " Entendido", ServicioNotificacion, "2")
        Dim cs As CSBuilder
        If Tipo.ToUpperCase  = "UPLOAD" Then
            
            NewNotificacion.AddButtonAction(Null, cs.Initialize.Color(Colors.Red).Bold.Append( "Descarga").PopAll, ServicioNotificacion, "1")
        else if Tipo.ToLowerCase ="VERSION" Then
            
        Else if Tipo.ToUpperCase = "MSG" Then
            'Msgbox(Body,Title)
            CallSubDelayed3(Main,"Msg",Body,Title)
            'Msgbox2Async(Body,Title,"ACEPTAR","","",modGeneral.BM,False)   
        else if Tipo.ToUpperCase ="GPS" Then
            CN.NotificarLatLon
        End If
        NewNotificacion.DeleteAction(ServicioNotificacion, "delete action")
        NewNotificacion.AutoCancel(True)
        
        Noti = NewNotificacion.Build(Title, Body, "tag",  Main)

        Noti.Notify(IdNotificacion)
            Log("NotificacionLocal Z")
            
    Catch
        Log(LastException)
    End Try
End Sub

and in main:
B4X:
private Sub Msg(T1 As String, T2 As String)

    Msgbox2Async(T1,T2,"ACEPTAR","","",modGeneral.BM,False)
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You cannot show a dialog from a service. You can show a high importance notification and depending on the device settings it might show as a popup.

If there is a foreground activity when the notification arrives then you can call a method with CallSub (or better using B4XPages) and show whatever you like.
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
it is posible know the activity active (in a foreground )
And include in ALL activitis the same code, (sub showmsgbox ) and callsub to the activity.active this method?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
No automatic way. You can check with IsPaused(ActivityName) the state of each activity.

And include in ALL activitis the same code, (sub showmsgbox ) and callsub to the activity.active this method?
Never duplicate code. Implement whatever you need in a class and create an instance of this class in each of the activities.
 
Upvote 0
Top