INSTALL_REFERRER not received before application launched

送分小仙女□ 提交于 2019-12-12 15:10:53

问题


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


回答1:


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.




回答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);



回答3:


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.



来源:https://stackoverflow.com/questions/28322000/install-referrer-not-received-before-application-launched

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!