8

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!!

Community
  • 1
  • 1
user1865027
  • 2,915
  • 4
  • 26
  • 56
  • As far as I know, the referrer feature is pretty much completely broken now (post 3.1) anyway. – kabuko Aug 07 '13 at 23:12
  • really? since when? I was still able to use the referrer feature earlier by this link `market://details?id=your.package.name&referrer=YourReferrerString` – user1865027 Aug 08 '13 at 16:55
  • I guess the new intent thing that introduced to Chrome might not complete yet. the documentation is shy to talk about more.... – user1865027 Aug 08 '13 at 16:57
  • It depends on the version of Google Play you have and I can't say I've tried recently, but last I checked it didn't work and I haven't heard anything to the contrary recently. If it works for you, then maybe my info is out of date. – kabuko Aug 08 '13 at 18:00
  • thanks for the info man! after days of trying, i think the new Chrome scheme is just not completed yet.... – user1865027 Aug 09 '13 at 21:12

1 Answers1

3

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>
akent
  • 3,829
  • 25
  • 27
  • I had some issue with this solution. The app was not always receiving the intent extra with the referrer. Finally I ended up using Branch Deeplink SDK which do this inanition to the deeplinking features – Sojan P R Sep 02 '15 at 18:30
  • "default referrer from Chrome is 'com.android.chrome" Thanks a ton for that. Another question in case the intent scheme does not work and the app is redirected to market,will the referrer be carried too? – Utsav Gupta Sep 28 '16 at 17:08