Android Question NB6 How to pass multiple information using Tag

Discussion in 'Android Questions' started by Anser, Jun 30, 2018.

  1. Anser

    Anser Well-Known Member Licensed User

    Hi,

    This is how we build the NB6 Notification. The 3rd parameter is the Tag
    Code:
    nb.Build(cSubject,cMsg,"Offers",HomePage).Notify(nNotificationCount)
    Checking the NB6 class, I understand that the 3rd parameter of nb.Build() is a String. I would like to pass few more information via Tag, may be a Map. For eg. in my app I receive few types of FCM Notifications. After receiving the FCM message on the device, the required activity will be called. For eg I will be sending a notification to the app user regarding an OFFER, While receiving the notification, an OFFER ID is also received. I would like to pass both information ie

    The Notification type ie "OFFER"
    OFFER ID for eg "123"

    At present this is how the HomePage's Activity_Resume sub handles the Notification when it is received via the call
    Code:
    nb.Build(cSubject,cMsg,"Offers",HomePage).Notify(nNotificationCount)
    Code:
    Sub Activity_Resume
        
    Dim in As Intent = Activity.GetStartingIntent
     
        
    If in.IsInitialized And in <> OldIntent Then
            OldIntent = 
    in
            
    Dim intentExtra As String
            
    If in.HasExtra("Notification_Tag"Then
                intentExtra = 
    in.GetExtra("Notification_Tag")
       
                
    If intentExtra = "Offers" Then 'The tag 'Offer Notification
       
                    
    ' What needs to be done here to get few more extra information passed via the notification
                    ' tag ie the OFFER ID too, so that I can pass all the required info to the right Activity
                    Dim mapParameters As Map    : mapParameters.Initialize
                    mapParameters.Put(
    "OfferID","123")
                    mapParameters.Put(
    "Title""What ever Title")
                    CallSubDelayed2(MyActivityName,
    "StartWithParameter",mapParameters)          
                
    End If
            
    End If
        
    End If
    End Sub
    As of now, there is no provision to set the parent activity of the called Activity, called from the Notification (ie when the user press the back key, the activity to be called). So to overcome this limitation, we need to call the HomePage first and from the Activity_Resume of the HomePage activity we need to call the required activity.

    Any help will be appreciated.

    Thanks
     
  2. DonManfred

    DonManfred Expert Licensed User

    put a jsonstring as the tag.

    for ex.

    Code:
    Sub fm_MessageArrived (Message As RemoteMessage)
        
    Log("Message arrived")
        
    Log($"Message data: ID ${Message.MessageId}, Data ${Message.GetData}"$)
        
    ' Message
        ' ID 0:1527930196160884%33f98919a3d06034
        ' Data {
        ' imgbig=http://basic4android.de/big.png,
        ' imgsmall=http://basic4android.de/small.png,
        ' body=this is the textbody,
        ' title=this is the Title
        '}
        Dim mapParameters As Map    : mapParameters.Initialize
        mapParameters.Put(
    "OfferID","123")
        mapParameters.Put(
    "Title""What ever Title")
        
    Dim jgen As JSONGenerator
        jgen.Initialize(mapParameters)

        
    Dim n As NB6
        n.Initialize(
    "default"Application.LabelName, "DEFAULT").AutoCancel(True)

        
    If Message.GetData.ContainsKey("imgbig"Then
            
    Dim j As HttpJob
            j.Initialize(
    "", Me)
            j.Download(Message.GetData.Get(
    "imgbig"))
            
    Wait For (j) JobDone(j As HttpJob)
            
    If j.Success Then
                
    Dim img_big As Bitmap
                img_big = j.GetBitmap
                n.LargeIcon(img_big)
            
    End If
            j.Release
        
    End If
        
    If Message.GetData.ContainsKey("imgsmall"Then
            
    Dim j As HttpJob
            j.Initialize(
    "", Me)
            j.Download(Message.GetData.Get(
    "imgsmall"))
            
    Wait For (j) JobDone(j As HttpJob)
            
    If j.Success Then
                
    Dim img_small As Bitmap
                img_small = j.GetBitmap
                n.SmallIcon(img_small)
            
    End If
            j.Release
        
    Else
            
    Dim smallbmp As Bitmap
            smallbmp.Initialize(
    File.DirAssets,"firebase24.png")
            n.SmallIcon(smallbmp)
        
    End If
        n.Build(Message.GetData.Get(
    "title"), Message.GetData.Get("body"), jgen.ToString, Main).Notify(4)

    End Sub
    This is such a notification (using special Images for small and big images in the notification.

    WhatsApp Image 2018-06-30 at 07.53.21.jpeg
     
    Last edited: Jun 30, 2018
    mangojack, Jorge M A and Anser like this.
  3. DonManfred

    DonManfred Expert Licensed User

    If the user then clicks on it. Get the json back from the tag and parse it with jsonparser.

    Code:
    Sub Activity_Resume
        
    'Log("Auth.currentUser = "&auth.CurrentUser)
        If auth.CurrentUser.IsInitialized Then
            
    Log("Auth.currentUser = "&auth.CurrentUser)
            
    'Auth_SignedIn(auth.CurrentUser)
        End If
      
    Dim in As Intent = Activity.GetStartingIntent
     
        
    If in.IsInitialized And in <> OldIntent Then
            OldIntent = 
    in
            
    Dim intentExtra As String
            
    If in.HasExtra("Notification_Tag"Then
                intentExtra = 
    in.GetExtra("Notification_Tag")
                          
    log("XTRA="&intentExtra)
                
    'If intentExtra = "Offers" Then 'The tag 'Offer Notification
                                        '{"OfferID":"123","Title":"What ever Title"}

                    
    Dim jp As JSONParser
                                jp.Initialize(intentExtra)
                                
    Dim root As Map = jp.NextObject
                                
    Dim OfferID As String = root.Get("OfferID")
                                
    Dim Title As String = root.Get("Title")
                  
    'CallSubDelayed2(MyActivityName,"StartWithParameter",root)       
                'End If
            End If
        
    End If
    End Sub
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice