3

I want to catch INSTALL_REFERRER intent at my own receiver. I implemented receiver

public class InstallReferrerReceiver extends BroadcastReceiver {

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

and add at Manifest

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

When i want to test receiver, i install my application(not launch) and send broadcast via adb

am broadcast -a com.android.vending.INSTALL_REFERRER --es "referrer" "utm_medium=partner&utm_campaign=partner_name"

But can't see any logs. After lounch, it work correct and receive intents.

From "Testing Google Play Campaign Measurement"

To broadcast the INSTALL_REFERRER intent to your application:

  1. Verify that your application is not currently running.
  2. Open a terminal and run this command: ...

But my receiver not receive intents, before i launch application first time. Is this a correct behavior? When i receive this intent if i install application from market with referrer params?

Thanks

Dehimb
  • 252
  • 3
  • 15

3 Answers3

4

On Android 3.1+ application's BroadcastReceiver (or any other component) will not be fired until user has launched the application at least once. Until then it is in the "stopped" state

That is an intended behaviour and prevents some security risks.

Drew
  • 3,307
  • 22
  • 33
  • I can't believe that. Wouldn't that render the "INSTALL_REFERRER" completely useless? The broadcast is always fired on install before the first launch so it can never be received?! – Nils Mar 27 '17 at 13:22
  • What do you mean by that ? What is the behaviour of this broadcast? The _fact that broadcast is fired_ is unrelated to _fact that it is not received_. It might be a sticky broadcast received immediately after process launch explicitly initiated by user – Drew Mar 27 '17 at 17:30
2

you must set flag Intent.FLAG_INCLUDE_STOPPED_PACKAGES when send broadcastintent.

Bundle extras = new Bundle();
extras.putString("referrer", referrer);
Intent intent = new Intent("com.android.vending.INSTALL_REFERRER");
intent.putExtras(extras);
intent.setPackage(packageChanged);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);
Android
  • 1,420
  • 4
  • 13
  • 23
AminTe
  • 21
  • 3
0

You adb command is not complete. Try with this one:

./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <your package>/<your package>.receiver.InstallReferrerReceiver --es "referrer" "utm_medium%3Dpartner%26utm_campaign%3Dpartner_name"

Note: the referrer should be url encoded.

Pablo
  • 1,368
  • 12
  • 18
  • Adb command correct, it works after first application launch. The answer at platform restrictions, as answered by Drew - application's BroadcastReceiver (or any other component) will not be fired until user has launched the application at least once – Dehimb Jul 15 '15 at 15:08