-1

I have to implement the referral linking functionality in my application like mCent application. For that I have done the following lines of code.

My application Manifest file. In the <application >..... </application> , I have done some entries for it.

 <service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
 <receiver
 android:name=".receivers.InstallReceiver"
 android:exported="true" >
 <intent-filter>
 <action android:name="com.android.vending.INSTALL_REFERRER" />
 </intent-filter>
 </receiver>

And My BrodcastRecevier class is as follow , please check it.

public class InstallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String rawReferrer = intent.getStringExtra("referrer");
        if (rawReferrer != null) {
            trackReferrerAttributes(rawReferrer, context);
        }
    }

    private void trackReferrerAttributes(String rawReferrer, Context context) {
        String referrer = "";

        try {
            referrer = URLDecoder.decode(rawReferrer, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return;
        }

        if (Strings.isNullOrEmpty(referrer)) {
            return;
        }

        Uri uri = Uri.parse('?' + referrer); // appends ? for Uri to pickup query string

        String memberCode;
        try {
            referringMember = uri.getQueryParameter("mcode");
        } catch (UnsupportedOperationException e) {
            return;
        }

        SharedPreferences.Editor editor = context.getSharedPreferences(
            BuildConfig.PACKAGE_NAME, Context.MODE_PRIVATE).edit();

        if (!Strings.isNullOrEmpty(memberCode)) {
            editor.putString(Constants.REFERRER_CODE, memberCode);
        }

        String referralMedium = uri.getQueryParameter("tc");
        if (!Strings.isNullOrEmpty(referralMedium)) {
            editor.putString("referral_medium", referralMedium);
        }

        editor.apply();
    }
}

But i am not receiving any referral from the above code... I have created the refferal link like this

 https://play.google.com/store/apps/details?id=tv.CaseGaurd&referrer=ravindrakushwaha

Is there is any error in my referral link above OR friends , what am i doing wrong in my BroadcastRecevier class or in Manifest file

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Edit your question, demonstrate how/where are you launching an intent or asking for the broadcast for the `InstallReceiver` to receive – Bonatti Jan 25 '16 at 10:41
  • @Bonatti ...Thanks for the suggestion.. But these Brodcast recevier need not any Intent to receive the event..As we know that,google play throws com.android.vending.INSTALL_REFERRER , when we installed the app than my class receive these from above code....My problem is that i am not receiving the data which i have created with my application link – android developer Jan 25 '16 at 10:49
  • I really amazed that why the people only down vote the question when any one ask...If they does not know the solution of the problem than why are they downvoting it...These site is for help not for the down voting man – android developer Jan 25 '16 at 10:50
  • [As a source, read this stackoverflow related topics answer](http://stackoverflow.com/questions/24866161/android-referral-tracking-not-working-with-google-play) – Bonatti Jan 25 '16 at 11:24

1 Answers1

2

From this documentation I found that the action filter is (in manifest):

 <!-- Used for install referrer tracking-->
  <receiver android:name="YOUR_RECEIVER"
 android:exported="true">
  <intent-filter>
      <action android:name="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
 </receiver>

Also be sure that your Receiver is in that real package ".receivers.InstallReceiver", but package com.example.app.receivers;... is your package really com.example.app?

(I considered you to be using the Google Play Store app)... also, about your downvotes, this is likely to bad wording on your question, or that you are not showing effort about your question, finally, note that this is a "free to use community forum", and that people are random...

Finally, put a breakpoint in the Receiver, send a broadcast (using adb for instance), and test that you are really not getting the broadcast.

Bonatti
  • 2,778
  • 5
  • 23
  • 42
  • Thanks for yours valueable effort – android developer Jan 25 '16 at 12:17
  • Did you solve your problem? And if you did, can you writte down what went wrong. Stackoverflow "works" as a repository for problems and solutions, so if this fixed/helped you fix the problem, use the "v" symbol to indicate that the question is answered. If not, edit your question, and add what is happening. – Bonatti Jan 25 '16 at 17:02
  • Thanks for yurs effort +1 , for it....Can you please tell me that is referral linking not works on already installed application ?? plz help me – android developer Feb 05 '16 at 08:59
  • What do you mean? The `"com.android.vending.INSTALL_REFERRER"` is for installations only. Do you want to check on new installations or all instalations? This broadcasted event is sent when the user clicks a link to your application, the Google Play intercepts the intent, and then enables the user to install it.... If you want to "count" all your installed applications, may I suggest using the statistics on `https://play.google.com/apps/publish/` – Bonatti Feb 05 '16 at 11:01
  • sir... Actually i want to get the data from the LINK on my SMS or MAIL... Either application is installed or not...Yet now i am getting the data from the link, only when he application is not installed on my device...,, But i want to get the data when the application is installed on my device – android developer Feb 09 '16 at 08:51
  • Like in my previous comment, the `INSTAL_REFERRER` is only sent when this happens: User clicks a Link to a Google Play store app. User agrees with installation. User downloads and install apps, Broadcast for that installation is sent. If you need some different scenario, then look into other broadcasts, or other filters you may use/need. – Bonatti Feb 11 '16 at 11:31
  • @Bonatti How can we check the referral linking..Any idea? – Ravindra Kushwaha Sep 19 '18 at 07:40
  • @RavindraKushwaha I dont understand what you are asking. The Answer already has the documentation link, and the `com.android.vending.INSTALL_REFERRER` is working as intended on pretty much every device I had ever worked with. Do note the following must be true: `1 -` Device has a Google Account registered `2 -` has ever opened Google Play `3 -` has installed with said application `4 - ` has internet connection during install – Bonatti Sep 19 '18 at 12:39
  • @Bonatti Thanks for input +1 for it..I have implemented the above code..Just want to check that referral is working or not..I need the google play store to check it.? – Ravindra Kushwaha Sep 19 '18 at 12:41
  • @RavindraKushwaha Yes. the referal will only be sent, when installing from the Google Play application, with the "referal link" [testing help](https://stackoverflow.com/questions/5890914/how-to-test-android-referral-tracking/6966718#6966718) and [another good answer on the topic](https://stackoverflow.com/questions/30103338/android-is-it-possible-to-get-install-referrer-programmatically) – Bonatti Sep 19 '18 at 14:48