Question

so I noticed according to here, you can put a link on the site and have user to click on it. If user had the app installed, app will be launched. If the app wasn't installed, Google Play Store will be launched and search for the particular package, which is a great feature!! but from my understanding, this will loose the ability to pass referral string to play store.

According to here, you can have a link like market://details?id=your.package.name&referrer=YourReferrerString. If a broadcast receiver is set in the app, you'll be able to catch the referrer string, but how can I achieve the same goal if I used the first method which is from here?

here is the only thread I can find that talks about the new (?) feature on Chrome, but it didn't seem to answer my question.

Thanks!!

Was it helpful?

Solution

Turns out to be quite simple. The default referrer from Chrome is 'com.android.chrome'. Override this by putting &referrer= after package in your intent:// URI, for example:

var g_intent = "intent://" + code + 
  "/#Intent;scheme=yourscheme;package=com.your.app&referrer=code%3D" + 
  code + ";launchFlags=268435456;end";

Here's a gist that explains the javascript part of the solution more fully and also falls back to a normal market link if the intent:// scheme doesn't work: https://gist.github.com/akent/dec1b4b7383436b4623e

And in your Java code:

public static class InstallReferrerReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String referrer = intent.getStringExtra("referrer");
        // Do things with your referrer here
    }
}

And in AndroidManifest.xml:

    <receiver android:name=".YourActivity$InstallReferrerReceiver" android:exported="true">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top