我在 Play 商店中有一个 android 应用程序。从引荐来源网址安装并直接从播放商店打开后,它挂起并且应用程序崩溃,就像在 UI 线程上做很多工作一样,我的清单中有两个广播接收器用于 INSTALL_REFERRER 一个用于分析目的,另一个用于设置一些警报。出于分析目的,我正在提取 utm 源、媒体、活动 id ......这是非常轻量级的操作,但我仍然在 IntentService 上进行操作,
代码
@Override
protected void onHandleIntent(Intent intent) {
getUtmValuesAndSave(UtmCreateService.this, intent);
}
private void getUtmValuesAndSave(Context context, Intent intent) {
String referrer = intent.getStringExtra(Constants.UTM_REFERRER);
String source = getSourceFromReferrer(referrer);
saveSourceInPreference(context, source);
}
private static String getSourceFromReferrer(String referrer) {
StringBuilder sourceBuilder = new StringBuilder();
String source = null;
try {
referrer = URLDecoder.decode(referrer, "UTF-8");
String[] utms = referrer.split("&");
String utm = getUtmValue(utms, Constants.UTM_SOURCE);
sourceBuilder.append(Constants.UTM_SOURCE).append("=").append(utm).append("&");
utm = getUtmValue(utms, Constants.UTM_CAMPAIGN);
sourceBuilder.append(Constants.UTM_CAMPAIGN).append("=").append(utm).append
("&");
utm = getUtmValue(utms, Constants.UTM_ANID);
sourceBuilder.append(Constants.SERVER_UTM_ADGROUPID).append("=").append(utm);
} catch (Exception e) {
e.printStackTrace();
}
source = sourceBuilder.toString();
return source;
}
/**
* read utm value for the given key
*
* @param utms utm string array, contains all the utm fields
* @param key key
* @return value of the key in utm
*/
private static String getUtmValue(String[] utms, String key) {
String utm = null;
boolean foundUtm = false;
for (String utm1 : utms) {
utm = utm1;
if (utm.contains(key)) {
foundUtm = true;
utm = utm.split("=")[1];
break;
}
}
if (!foundUtm) {
utm = "Null";
}
return utm;
}
** 显现 **
<receiver
android:name=".receiver.AnalyticsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.AlarmStartReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
这里可能是什么问题?如果我直接从 Play 商店安装应用程序(没有引荐来源网址,那么它可以正常工作)。我检查了 logcat 日志,我看到接收者多次调用
编辑
我用这个 adb 命令测试了应用程序,adb shell am broadcast -a com.android.vending.INSTALL_REFERRER --es "referrer" "utm_source%3Dgoogle%26utm_medium%3Dcpc%26utm_term%3Dtest%2520fund%26utm_content%3Dnew%2520ad%26utm_campaign%3Dtest%26anid%3Dadmob;
发现它反复调用 INSTALL_REFERRER 接收器。
更新,从 Play 商店安装时记录
MultipleInstallBroadcastReceiver.onReceive(MultipleInstallBroadcastReceiver.java:31)
02-27 17:11:46.840 21946-21946/my.package.name W/logd: Dropped 2
02-27 17:11:46.840 21946-21946/my.package.name E/art: at my.package.name.receiver.CommonAnalyticsTrackingReceiver.onReceive(CommonAnalyticsTrackingReceiver.java:29)
02-27 17:11:46.840 21946-21946/my.package.name W/logd: Dropped 3
02-27 17:11:46.840 21946-21946/my.package.name E/art: at my.package.name.receiver.CommonAnalyticsTrackingReceiver.onReceive(CommonAnalyticsTrackingReceiver.java:29)
02-27 17:11:46.840 21946-21946/my.package.name W/logd: Dropped 2
02-27 17:11:46.840 21946-21946/my.package.name E/art: at com.appsflyer.MultipleInstallBroadcastReceiver.onReceive(MultipleInstallBroadcastReceiver.java:31)
02-27 17:11:46.840 21946-21946/my.package.name W/logd: Dropped 2
02-27 17:11:46.840 21946-21946/my.package.name E/art: at my.package.name.receiver.CommonAnalyticsTrackingReceiver.onReceive(AnalyticsTrackingReceiver.java:29)
02-27 17:11:46.840 21946-21946/my.package.name W/logd: Dropped 3
这是从 Play 商店安装时的日志,大约 1000 次。