我已完成tutorial并且能够debug and send broadcasts manually
但是我不能用另一个自定义接收器拦截引用者数据。它只是不会在传入的广播com.android.vending.INSTALL_REFERRER
上触发。
如果我向/com.google.android.gms.analytics.CampaignTrackingReceiver
自定义接收器发送广播,请不要看到它。另外,发送到co.primesignals.android.primesignalsapp.campaign.LaunchReceiver
的工作正常。但谷歌将该广播发送给自己的接收者...
如何正确实施自定义接收器来拦截广告系列引荐来源?
清单:
...
<uses-permission android:name="android.permission.WAKE_LOCK" />
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
<!--Used for Google Play Store Campaign Measurement-->
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"
android:enabled="true"
android:exported="false"/>
<receiver
android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<receiver android:name=".campaign.LaunchReceiver" //custom receiver
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
LaunchReceiver:
public class LaunchReceiver extends BroadcastReceiver {
public static final String INSTALL_REFERRER_ACTION = "com.android.vending.INSTALL_REFERRER";
public static final String REFERRER = "referrer";
public static final String TAG = "GAv4 app ->";
@Override
public void onReceive(Context context, Intent intent) {
android.util.Log.d(TAG, "LaunchReceiver.onReceive");
final String action = intent.getAction();
if (!TextUtils.isEmpty(action) && INSTALL_REFERRER_ACTION.equals(action)) {
android.util.Log.d(TAG, String.format("LaunchReceiver.onReceive action=%s", action));
String referrer = intent.getStringExtra(REFERRER);
if (!TextUtils.isEmpty(referrer)) {
android.util.Log.d(TAG, String.format("LaunchReceiver.onReceive referrer=%s", referrer));
SPManager.add(context, REFERRER, referrer);
CampaignData.parseAndSaveData(context, referrer);
}
}
new CampaignTrackingReceiver().onReceive(context, intent);
}
}
我用来传播广播的ADB shell命令:
am broadcast -a com.android.vending.INSTALL_REFERRER -n "[package]/com.google.android.gms.analytics.CampaignTrackingReceiver" --es referrer "[referrer value]" -> this is not handled by custom receiver
am broadcast -a com.android.vending.INSTALL_REFERRER -n "[package]/co.primesignals.android.primesignalsapp.campaign.LaunchReceiver" --es referrer "[referrer value]" -> this works perfect but google wont send this broadcast
答案 0 :(得分:1)
Make exported =&#34; true&#34;适用于AnalyticsReceiver和CampaignTrakingReceiver。有关详情,请参阅https://developers.google.com/analytics/devguides/collection/android/v4/campaigns