How to get referrer URL for apps downloaded from o

2019-05-26 15:27发布

问题:

I've found some solutions to track referrer URL from the market, but my apps aren't in the market.

Is there a way to get the referrer URL for applications downloaded from private sites?

回答1:

To get referrer, you need to register your receiver for that. After installation, a broadcast is fired which you need to catch by following code.

First take a look at Android Native Application Tracking Overview

1. Create a Receiver

public class ReferrerReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Bundle extras = intent.getExtras();
        String referrerString = extras.getString("referrer");

        Log.i("Home", "Referrer is: " + referrerString);
    }
}

2. Register in Manifest file

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