Install referrer not working in some redmi devices

Viewed 1645

I need to track install referrals for my android app. It's working fine in most of the devices. But in Redmi device, the broadcast is not getting triggered. I tested it with Redmi Note 4

I have tested it both from via ADB as well as play store. Both don't trigger the broadcast in Redmi device

Below is the code that I am using

public class ReferrerReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
           Log.d("Broadcast", "RECEIVED!");
        }
}


<receiver
    android:name=".receiver.ReferrerReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER"/>
    </intent-filter>
</receiver>

Please suggest if someone faced the same issue and got some solution??

5 Answers

You could solve this issue by using the Play Install Referrer Library api 1.0 from Google. I did it this way and it works fine on devices that block the auto start by default.

First Add the following line to the dependencies section of the build.gradle file for your app:

dependencies {
...
compile 'com.android.installreferrer:installreferrer:1.0'

}

Then you should implement the interface InstallReferrerStateListener and its methods onInstallReferrerSetupFinished and onInstallReferrerServiceDisconnected in your Activity

Call the newBuilder() method to create an instance of InstallReferrerClient class.

Call the startConnection() to establish a connection to Google Play.

The startConnection() method is asynchronous, so you must override InstallReferrerStateListener to receive a callback after startConnection() completes.

You should also Override the onInstallReferrerSetupFinished() method to handle lost connections to Google Play. For example, the Play Install Referrer Library client may lose connection if the Play Store service is updating in the background. The library client must call the startConnection() method to restart the connection before making further requests.

Example:

InstallReferrerClient mReferrerClient

mReferrerClient = InstallReferrerClient.newBuilder(this).build();
mReferrerClient.startConnection(new InstallReferrerStateListener() {
@Override
public void onInstallReferrerSetupFinished(int responseCode) {
    switch (responseCode) {
        case InstallReferrerResponse.OK:
            // Connection established
            break;
        case InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
            // API not available on the current Play Store app
            break;
        case InstallReferrerResponse.SERVICE_UNAVAILABLE:
            // Connection could not be established
            break;
    }
}
@Override
public void onInstallReferrerServiceDisconnected() {
    // Try to restart the connection on the next request to
    // Google Play by calling the startConnection() method.
}
});

After you have established a connection to the Play Store app:

Use the synchronized getInstallReferrer() method to return ReferrerDetails. Then, use methods in ReferrerDetails to get install timestamps and a referrer url.

ReferrerDetails response = mReferrerClient.getInstallReferrer();
response.getInstallReferrer();
response.getReferrerClickTimestampSeconds();
response.getInstallBeginTimestampSeconds();

For further info: https://developer.android.com/google/play/installreferrer/library

Hope this helps!!

Related