Android Question [SOLVED] New alternative to com.android.vending.INSTALL_REFERRER

JackKirk

Well-Known Member
Licensed User
Longtime User
Using this post by echapeta:

https://www.b4x.com/android/forum/t...-referral-from-google-play.66355/#post-451082

I have managed to pass "referrer" strings from a webpage href to an app as it is launched for the first time via the Google Play Store OPEN button.

Testing this has revealed a curious little quirk: if the OPEN button is pressed too quickly after it first appears (i.e. immediately after the app is installed) the app can miss getting the "referrer" string. If the app is closed and OPEN pressed again it generally works properly - but this is definitely NOT a good user experience.

Doing some googling about this issue (which seems to be a quite well known problem) I came across this article:

https://android-developers.googleblog.com/2017/11/google-play-referrer-api-track-and.html

which is all of 3 days old - hot off the press!

In it a Google engineer describes a new API for accessing the "referrer" string which presumably is a lot more robust than the current mechanism.

It is all above my pay-grade however, so 3 questions:

1. Does this need to be wrapped or can it be accessed via a bit of reflection skullduggery.
2. If the answer to (1) is a bit of skullduggery - can anyone tell me how.
3. If the answer to (1) is wrapping - is there a guru out there who is willing to do it?

Thanks in anticipation...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Download the aar file and copy it to the additional libs folder: https://dl.google.com/dl/android/ma...r/installreferrer/1.0/installreferrer-1.0.aar

2. Add permission with manifest editor:
B4X:
AddPermission(com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE)

3. Add this code:
B4X:
#AdditionalJar: installreferrer-1.0.aar
Sub Process_Globals
   Private InstallReferrerClient As JavaObject
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     Dim context As JavaObject
     context.InitializeContext
     InstallReferrerClient.InitializeStatic("com.android.installreferrer.api.InstallReferrerClient")
     InstallReferrerClient = InstallReferrerClient.RunMethodJO("newBuilder", Array(context)).RunMethod("build", Null)
     Dim listener As Object = InstallReferrerClient.CreateEventFromUI("com.android.installreferrer.api.InstallReferrerStateListener", "listener", Null)
     InstallReferrerClient.RunMethod("startConnection", Array(listener))
   End If
End Sub

Sub Listener_Event (MethodName As String, Args() As Object) As Object
   If MethodName = "onInstallReferrerSetupFinished" Then
     Dim status As Int = Args(0)
     Select status
       Case 3
         Log("developer error")
       Case 2
         Log("feature not supported")
       Case 0
         Log("OK!")
         Dim ReferrerDetails As JavaObject = InstallReferrerClient.RunMethod("getInstallReferrer", Null)
         Log(ReferrerDetails.RunMethod("getInstallBeginTimestampSeconds", Null))
         Log(ReferrerDetails.RunMethod("getInstallReferrer", Null))
         Log(ReferrerDetails.RunMethod("getReferrerClickTimestampSeconds", Null))
       Case Else
         Log("Not available")
     End Select
   End If
   Return Null
End Sub
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Woo Hoo - the ultimate guru - thanks Erel, I will test it out tomorrow and report back.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Erel, I copied your code and customised it for my app - happy to report that it now works flawlessly - I can't trip it up!

Thanks once again...

If only iOS had a similar mechanism...
 
Upvote 0
Top