Install referrer not working in some redmi devices
Asked Answered
M

5

11

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

Meatiness answered 27/7, 2017 at 13:54 Comment(2)
have you tried if (Objects.equals(intent.getAction(), Intent.ACTION_INSTALL_PACKAGE)) { Log.d("Broadcast", "RECEIVED!"); } inside your receiverStrove
@AshutoshSagar The issue i am facing is that the onReceive itself is not getting calledMeatiness
B
3

Is your app in the list of "protected apps" that are allowed to run in the background? If not, it won't get automatically started. This is a problem on devices like Xiaomi, Huawei and others. There should be a settings page in "Settings->Apps-Security" that allows you to add your app to a list of apps that are allowed to autostart, run in the background, etc. Each device manufacturer does this a bit differently, but in general we see this on Chinese devices as a way to preserve battery life.

See also:

Baynebridge answered 4/8, 2017 at 15:19 Comment(0)
P
0

In Redmi device some android applications needs permissions. Please allow the permissions manually in the device. By using app permissions option in your device give all permissions. It may work which i had observed for my app.

Purkey answered 5/8, 2017 at 12:53 Comment(0)
E
0

I use Redmi 3 Pro and always have trouble with Android Permission. Xiaomi devices use custom ROM that caused permission request buggy sometimes.

The overlay service permission is always forced set to Denied in every app that I installed. I must manually Allow it.

Nice workaround I found to let Xiaomi devices auto start permission: How to get MIUI Security app auto start permission programmatically?

Enrich answered 6/8, 2017 at 14:59 Comment(0)
L
0

There is always some issues with the miui due to their restrictions on background processes you can turn them on here is how it goes

1: Go to settings --> manage apps' battery usage --> choose apps. From there, pick all the apps you want to receive push notifications and select "No restrictions."

2: Go to settings --> permissions --> autostart. From there, pick the apps you want, and toggle the switch to turn it on.

3: Lock the app in the "recent apps"/ "app overview" plane. Do so by first opening the apps, then press the "recent apps/overview button" (that's the square button on stock Android, or the button with three horizontal lines on the Mi Mix). From there, find the app you want to receive notifications, pull down on it to "lock it", so it never gets cleared.

4: This last step requires Developer Options privileges. To enable that, go to settings (man... I'm getting tired of typing "go to settings" ...) --> about phone tap on MIUI version tab like eight times. You should then get a little message saying "you are now a developer." Then head back out to settings, go to developer option, scroll to nearly the bottom, find "memory optimization," and turn it off.

Again, maybe step 4 is all you need.

Lavinialavinie answered 7/8, 2017 at 3:3 Comment(0)
C
-3

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

Couchant answered 25/1, 2019 at 18:38 Comment(4)
Though the link is helpful please also add more details and examples to the answer itselfSaurischian
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewIdentic
@DavidMaze Thanks, please check my edit, I've added more details and example.Couchant
I have tried this, it is not working on a few of the redmi devicesCasta

© 2022 - 2024 — McMap. All rights reserved.