1

All I want to call receiver on install of APK and get Referrer of it, I have tried to do this, here is my code of receiver class:

public class InstallReferrerReceiver extends BroadcastReceiver {
String TAG = "InstallReferrerReceiver";

@Override
public void onReceive(Context context, Intent intent) {
    String referrer = intent.getStringExtra("referrer");
    Log.d(TAG, "refferer" + referrer);
    //Use the referrer
}}

And here is the Manifest Class:

    <receiver
        android:name="com.installtracksdk.InstallReferrerReceiver"
        android:exported="true"
        android:permission="android.permission.INSTALL_PACKAGES">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_INSTALL" />
            <action android:name="android.intent.action.PACKAGE_ADDED" />
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>
Zaedian
  • 251
  • 5
  • 24
Sanjay
  • 574
  • 6
  • 16

2 Answers2

0

try following code:

     <intent-filter>
        <category android:name="android.intent.category.DEFAULT" />
        <action android:name="android.intent.action.PACKAGE_ADDED"  />
        <action android:name="android.intent.action.PACKAGE_CHANGED" />
        <action android:name="android.intent.action.PACKAGE_INSTALL" />
        <action android:name="android.intent.action.PACKAGE_REMOVED" />
        <action android:name="android.intent.action.PACKAGE_REPLACED" />
        <data android:scheme="package" />
    </intent-filter>
Firoz Jaroli
  • 505
  • 5
  • 11
0

in manifest file:

<receiver android:name=".YourReceiver">
<intent-filter>
    <action android:name="android.intent.action.PACKAGE_INSTALL" />
    <action android:name="android.intent.action.PACKAGE_ADDED" />
    <data android:scheme="package"/>
</intent-filter>

and in java code :

IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
        intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
        intentFilter.addDataScheme("package");
        registerReceiver(br, intentFilter);

this will work 7.1 and below devices .On Android 8.0+, you cannot register for those broadcasts in the manifest.

Check this for more detail:link

aj0822ArpitJoshi
  • 1,142
  • 1
  • 9
  • 25