Android Question [solved] Firebase AppInvites

DonManfred

Expert
Licensed User
Longtime User
I am creating this thread because i am writing a wrap for the Firebase AppInvites and i need some help.

Hopefully one of you know the answer.

In the moment i stuck finding the right import to use in #additionaljar for the Firebase DynamicLinks


The 1st version of the lib is attached including a example project.

If anyone have a hint what i should use in the #additionalar: please share
 
Last edited:

fredo

Well-Known Member
Licensed User
Longtime User
Nice.
B4X:
#-PrepMessage.btnSend_Click
#-  x67a, DeepLink=https://yourapp.com?utm_content=content&utm_campaign=campaign&at=AffiliateId&ct=CampaignToken&pt=ProviderToken&sd=description&si=imageUrl&st=title&afl=http%3A%2F%2Ffallback&amv=1&apn=b4a.example.fibainv&ibi=unknownparameter&ifl=fallbackurl&imv=1&isi=appstoreID&ius=customscheme&ipbi=ipadBundleId&ipfl=iPadFallbackurl&utm_term=term&utm_medium=medium&utm_source=source
#-  x67a, Authority=yourapp.com
#-  x67a, EncodedAuthority=yourapp.com
#-  x67a, EncodedFragment=null
#-  x67a, EncodedPath=
#-  x67a, EncodedQuery=utm_content=content&utm_campaign=campaign&at=AffiliateId&ct=CampaignToken&pt=ProviderToken&sd=description&si=imageUrl&st=title&afl=http%3A%2F%2Ffallback&amv=1&apn=b4a.example.fibainv&ibi=unknownparameter&ifl=fallbackurl&imv=1&isi=appstoreID&ius=customscheme&ipbi=ipadBundleId&ipfl=iPadFallbackurl&utm_term=term&utm_medium=medium&utm_source=source
#-  x67a, EncodedSchemeSpecificPart=//yourapp.com?utm_content=content&utm_campaign=campaign&at=AffiliateId&ct=CampaignToken&pt=ProviderToken&sd=description&si=imageUrl&st=title&afl=http%3A%2F%2Ffallback&amv=1&apn=b4a.example.fibainv&ibi=unknownparameter&ifl=fallbackurl&imv=1&isi=appstoreID&ius=customscheme&ipbi=ipadBundleId&ipfl=iPadFallbackurl&utm_term=term&utm_medium=medium&utm_source=source
#-  x67a, EncodedUserInfo=null
#-  x67a, Fragment=null
#-  x67a, Host=yourapp.com
#-  x67a, LastPathSegment=null
#-  x67a, Path=
#-  x67a, Query=utm_content=content&utm_campaign=campaign&at=AffiliateId&ct=CampaignToken&pt=ProviderToken&sd=description&si=imageUrl&st=title&afl=http://fallback&amv=1&apn=b4a.example.fibainv&ibi=unknownparameter&ifl=fallbackurl&imv=1&isi=appstoreID&ius=customscheme&ipbi=ipadBundleId&ipfl=iPadFallbackurl&utm_term=term&utm_medium=medium&utm_source=source

#-  x72, trying fbdl.buildShortDynamicLink

#-fbdl_onComplete
#-  x67c, task beendet
#-  x67c, Reloaded

#-fbdl_onFailure

B4X:
' Another look at the Deeplink result
DeepLink=https://yourapp.com
            ?utm_content=content
            &utm_campaign=campaign
            &at=AffiliateId
            &ct=CampaignToken
            &pt=ProviderToken
            &sd=description
            &si=imageUrl
            &st=title
            &afl=http%3A%2F%2Ffallback
            &amv=1
            &apn=b4a.example.fibainv
            &ibi=unknownparameter
            &ifl=fallbackurl
            &imv=1
            &isi=appstoreID
            &ius=customscheme
            &ipbi=ipadBundleId
            &ipfl=iPadFallbackurl
            &utm_term=term
            &utm_medium=medium
            &utm_source=source

Now for the "#-fbdl_onFailure"
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
For the new Invitation feature you need to add one or both of these lines
B4X:
#additionaljar: com.google.firebase:firebase-invites
#AdditionalJar: com.google.firebase:firebase-appindexing

and then in the invite activity on button click

B4X:
    invite.Initialize("","Einladung")
    invite.DeepLink = dynlink.UriStr
    invite.Message = "Dies ist eine Einladung"
    invite.CallToActionText = "TestInvite"
    invite.build

I choosed one contact (me) using SMS... It does work. I got a SMS with a short url....
But then it crashes

 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Another try with an email (and updated lib in the meantime)


Please note the new code used in PrepMessage:

B4X:
    ToastMessageShow("Message sent", True)

    invite.Initialize("Invite","Einladung")
    invite.DeepLink = dynlink.UriStr
    invite.Message = cs.Initialize.Typeface(Typeface.FONTAWESOME).Color(0xFF01FF20).Size(40).Append(Chr(0xF17B) & " Einladung " & Chr(0xF17B)).PopAll
    invite.CallToActionText = cs.Initialize.Typeface(Typeface.FONTAWESOME).Color(0xFF01FF20).Size(40).Append(Chr(0xF17B) & " Einladung " & Chr(0xF17B)).PopAll
    invite.build

End Sub
Sub Invite_onInvite(invites As List)
    Log($"Invite_onInvite(${invites})"$)
End Sub

The eMail arrived has a Link inside

Install this Application
https://t62hm.app.goo.gl/i/888939569991-fca7b982-a966-4ac6-99c0-eec2c6df2415

For sure it will not reach any valid app on Playstore as my app is not yet published.

But it seems to work

Please find updated Lib V0.15 on #1
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I tried to click the link in Android in my eMail-Client... The app crashes
Ok, build some checks, getting Bundle data from the Intent, figuring out....

Note that i clicked the Link in the eMail.
for about 10-20 seconds i got shown this




But then the app get started....

The latest results :


What should i say? I like to say



The interesting lines are

The event fbdl_onDynamicLink gets a Map which is printed here to the log

and


The resulting Map can be optimized
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Latest result

B4X:
InviteMap: (MyMap) {DEEP_LINK=https://t62hm.app.goo.gl?sd=description&si=imageUrl&st=title&link=https%3A%2F%2Ffbdl.basic4android.de%2Fsecure%2Ftest%2F, INVITATION_ID=888939569991-fca7b982-a966-4ac6-99c0-eec2c6df2415, OPENED_FROM_PLAY_STORE=false}

Looks good

INVITATION_ID=888939569991-fca7b982-a966-4ac6-99c0-eec2c6df2415 is the same as i got after i sent the invitation... At this point i need to store the ID (which i did not) to be able to recognize the ID later when someone opened my app from a Invitationlink....

I like it
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
My results are giving me some informations on how we need to care about all.

- At the time we are generating the Invitation we know what parameters we used inside the parameters. We need to save them for later reference. I suggest a database or so....
- After the invitation we get a result with one or more (it is a List) invitation-IDs. We need to same them for later reference. we should save a reference to the parameters we saved in the first step. In my example i got the ID 888939569991-fca7b982-a966-4ac6-99c0-eec2c6df2415
- When the app gets started by a referal-link we need to check the invitemap in the Event. Here we found the INVITATION_ID inside the Map. In my case i got 888939569991-fca7b982-a966-4ac6-99c0-eec2c6df2415 (o wonder ;-)).
- Now we can use the INVITATION_ID to check which parameters we saved.
Or we just use the infos given in the Event fbdl_onDynamicLink


Code used to check the intent in activity_create of the main activity

B4X:
    Activity.LoadLayout("Layout1")
    fbdl.Initialize("fbdl")
    Dim iStart As Intent = Activity.GetStartingIntent
    Log($"#-  intent0, ${iStart}"$)
    edtlog.Text = edtlog.Text&CRLF&iStart      
    If iStart <> Null Then
        Dim task As JavaObject = fbdl.getDynamicLinkFromIntent(iStart)
        Do While task.RunMethod("isComplete", Null) = False
            Log($"#-  intent1, sleep(100)"$)
            edtlog.Text = edtlog.Text&CRLF&"sleep"
            Sleep(100)
        Loop
        Log($"#-  intent2, task beendet"$)
      
        Dim invitemap As Map = fbdl.getBundleFromIntent(iStart) ' This is the interesting line. and the map returning for sure :D
        Log("InviteMap: "&invitemap)
        edtlog.Text = edtlog.Text&CRLF&iStart.Action
        'edtlog.Text = edtlog.Text&CRLF&iStart.ExtrasToString
        edtlog.Text = edtlog.Text&CRLF&invitemap
  
        If iStart.Action.Trim.Length <> 0 Then
            Log($" "$)
            Log($"  x28, DeepLinkActivity.Activity_Resume"$)
            'Log($"    x29, iStart.Action=${iStart.Action}"$ )
            'Log($"    x31, getBundleFromIntent=${iStart.ExtrasToString}"$ )
          
            ' ...
          
        End If
    End If

And the needed subs

B4X:
Sub fbdl_onBundleInfo(inviteBundle As Map)
    Log($"fbdl_onBundleInfo(${inviteBundle})"$)  
End Sub
Sub fbdl_onDynamicLink(link As Map)
    Log($"fbdl_onDynamicLink(${link})"$)
End Sub

PD: Please find the newest library V0.16 in Post #1
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I did changed something in the lib in the meantime....
I had a deeper look at the Invitationbuilder and extended it.
I also send out a new Invitation to your email, @fredo
Please have the app (see private conversation) installed before starting it from the link.

The app should show something in the edittext. Please copy all and paste it here. I want to see if "Additional Parameters" are beeing transported
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
So far i found no solution for the Build of the short dynamic link.
We could probably use the http-rest api to get it...

But away from that i thought about the invitation id and how to connect them to some setting using an small api....

I ended up in a small php-script and a database behind to store data for a invitation-id and to get the data for a invitationid

The Sender is adding the invitationid together with the returnvalue when inviting someone....

And on the Receiversite (when the app is started by a deeplink then the app can call the same server to get the invitationdata...


{"CodeGiven":"888939569991-41fae34e-f62d-4b6c-a7be-947dc90279cb","Value":"Hello world!"}
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Uddate about the Deeplink´s LINK...

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    fbdl.Initialize("fbdl")
    editInvitevalue.Text = ""
    Dim iStart As Intent = Activity.GetStartingIntent
    Log($"#-  intent0, ${iStart}"$)
    edtlog.Text = edtlog.Text&CRLF&iStart     
    If iStart <> Null Then
        Dim task As JavaObject = fbdl.getDynamicLinkFromIntent(iStart)
        Do While task.RunMethod("isComplete", Null) = False
            Log($"#-  intent1, sleep(100)"$)
            edtlog.Text = edtlog.Text&CRLF&"sleep"
            Sleep(100)
         
        Loop
        Log($"#-  intent2, task beendet"$)
     
        Dim invitemap As Map = fbdl.getBundleFromIntent(iStart)
        If invitemap <> Null Then
            Log("InviteMap: "&invitemap)
            Dim values() = Regex.Split("&",invitemap.Get("DEEP_LINK"))
            For Each val As String In values
                If val.StartsWith("link=") Then
                    Dim link As String = su.DecodeUrl(val.SubString(val.IndexOf2("=",0)+1),"utf8")
                    Log(link)
                    'Log(su.DecodeUrl(link,"utf8"))
                End If
                Log("Value: "&val)
            Next
            Dim code As String = invitemap.Get("INVITATION_ID")
            Dim j As HttpJob
            j.Initialize("",Me)
            j.Download2("https://domain",Array As String("action","getraw","invcode",code,"deviceID",Starter.DeviceID))
            Wait For (j) JobDone(job As HttpJob)
            If job.Success Then
                Log(job.GetString)
                editInvitevalue.Text = job.GetString
                ' {"Beschreibung":"Bla bla bla","PromoCode":"xyz","PromoID":15}
            Else
                Log(job.ErrorMessage)
            End If
            job.Release

            edtlog.Text = edtlog.Text&CRLF&iStart.Action
            edtlog.Text = edtlog.Text&CRLF&invitemap
 
            If iStart.Action.Trim.Length <> 0 Then
                Log($" "$)
                Log($"  x28, DeepLinkActivity.Activity_Resume"$)
                'Log($"    x29, iStart.Action=${iStart.Action}"$ )
                'Log($"    x31, getBundleFromIntent=${iStart.ExtrasToString}"$ )
         
                ' ...
            End If
            If link.Trim <> "" Then
                Dim Intent1 As Intent
                Intent1.Initialize2(link, 0)
                Log("Starte Deeplink-LINK")
                Log(link)
                StartActivity(Intent1)
            End If
        End If
    End If

End Sub

The interesting lines are
B4X:
        Dim invitemap As Map = fbdl.getBundleFromIntent(iStart)
        If invitemap <> Null Then
            Log("InviteMap: "&invitemap)
            Dim values() = Regex.Split("&",invitemap.Get("DEEP_LINK"))
            For Each val As String In values
                If val.StartsWith("link=") Then
                    Dim link As String = su.DecodeUrl(val.SubString(val.IndexOf2("=",0)+1),"utf8")
                    Log(link)
                    'Log(su.DecodeUrl(link,"utf8"))
                End If
                Log("Value: "&val)
            Next


and these lines too
B4X:
            If link.Trim <> "" Then
                Dim Intent1 As Intent
                Intent1.Initialize2(link, 0)
                Log("Starte Deeplink-LINK")
                Log(link)
                StartActivity(Intent1)
            End If

You now get forwarded to the Activity based on the intent-filter in the manifest....

Though i dont think we really need it... But it is the only "direct way" to transport infos to the app using the Deeplink... In form of a LINK (URL) inside the DeepLink.

For me my solution (see my last post) is OK...
But if you want to "handle" the link. Now you know how to do.

In fact this is what the documentation tells about the Deeplink. Check it in every activity if the intent contains a Invitebundle, get the deeeplink, handle the results.

https://firebase.google.com/docs/dynamic-links/android/receive?authuser=0

B4X:
FirebaseDynamicLinks.getInstance()
        .getDynamicLink(getIntent())
        .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
            @Override
            public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                // Get deep link from result (may be null if no link is found)
                Uri deepLink = null;
                if (pendingDynamicLinkData != null) {
                    deepLink = pendingDynamicLinkData.getLink();
                }


                // Handle the deep link. For example, open the linked
                // content, or apply promotional credit to the user's
                // account.
                // ...

                // ...
            }
        })

Handle the deep link. For example, open the linked content, or apply promotional credit to the user's account.

This post is about to handle the deeplink
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…