我花了最后两天,试图找到一种解决方法。
我需要预先配置取决于介和自谷歌发挥我的应用程序播放在安装应用时安装参照意图,我创建了自己的接收器这项任务。 为清单声明和接收器中的代码是:
舱单申报:
<receiver
android:name="my.package.CustomReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
而CustomReceiver的简化代码:
public class CustomReceiver extends BroadcastReceiver {
private static final String CAMPAIGN_SOURCE_PARAM = "utm_source";
@Override
public void onReceive(Context context, Intent intent) {
Log.d("debug", "waking receiver");
Uri uri = intent.getData();
getReferrerMapFromUri(uri);
new CampaignTrackingReceiver().onReceive(context, intent);
}
void getReferrerMapFromUri(Uri uri) {
MapBuilder paramMap = new MapBuilder();
// If no URI, return an empty Map.
if (uri == null) {
Log.d("debug", "intent null");
return;
}
if (uri.getQueryParameter(CAMPAIGN_SOURCE_PARAM) != null) {
// MapBuilder.setCampaignParamsFromUrl parses Google Analytics
// campaign
// ("UTM") parameters from a string URL into a Map that can be set
// on
// the Tracker.
paramMap.setCampaignParamsFromUrl(uri.toString());
Log.d("debug", paramMap.get(Fields.CAMPAIGN_SOURCE));
// If no source parameter, set authority to source and medium to
// "referral".
} else if (uri.getAuthority() != null) {
paramMap.set(Fields.CAMPAIGN_MEDIUM, "referral");
paramMap.set(Fields.CAMPAIGN_SOURCE, uri.getAuthority());
}
}
}
就这样。 我送广播安装意图与亚行shell命令,但它没有得到根本激活。 我使用谷歌分析V3。
先感谢您!