Answers:
最简单的方法是使用adb
。您不必编写任何代码。
只需在终端中运行:
adb shell
am broadcast -a com.android.vending.INSTALL_REFERRER -n <your.package>/.<path.up.until.your.BroadcastReceiver> --es "referrer" "utm_source=test_source\&utm_medium=test_medium\&utm_term=test_term\&utm_content=test_content\&utm_campaign=test_name"
这是我的确切行:
am broadcast -a com.android.vending.INSTALL_REFERRER -n net.lp.collectionista/.util.broadcast_receivers.FacadeBroadcastReceiver --es "referrer" "utm_source=test_source\&utm_medium=test_medium\&utm_term=test_term\&utm_content=test_content\&utm_campaign=test_name"
但您BroadcastReceiver
可能需要成为AnalyticsReceiver
,即
对于Google Analytics(分析)v2:
com.your.package / com.google.analytics.tracking.android.CampaignTrackingReceiver
对于Google Analytics v3:
com.your.package / com.google.android.apps.analytics.AnalyticsReceiver
对于Google Analytics(分析)v4:
com.your.package / com.google.android.gms.analytics.CampaignTrackingReceiver
正如Luigi所说,您也可以省去"-n"
componentname部分,但随后设备上的每个应用程序都会收到推荐。这可以是一个很好的额外测试,以查看是否BroadcastReceiver
可以正确找到您。
我看到的输出(尤其是最后一行很重要):
05-13 17:28:08.335: D/Collectionista FacadeBroadcastReceiver(8525): Receiver called
05-13 17:28:08.335: V/Collectionista FacadeBroadcastReceiver(8525): Receiver called with action: com.android.vending.INSTALL_REFERRER
05-13 17:28:08.365: D/GoogleAnalyticsTracker(8525): Stored referrer:utmcsr=test_source|utmccn=test_name|utmcmd=test_medium|utmctr=test_term|utmcct=test_content
adb shell <enter> am broadcast..
。我adb shell am broadcast...
输错了,它什么也没输出。
没有!您有几种方法可以测试它有此格式的意图手动发送广播
Intent i = new Intent("com.android.vending.INSTALL_REFERRER");
//Set Package name
i.setPackage("com.package.yourapp");
//referrer is a composition of the parameter of the campaing
i.putExtra("referrer", referrer);
sendBroadcast(i);
以上命令都不适合我。在尝试了许多命令组合之后,下面的命令对我有用:
./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <your package>/<your package>.<your BroadcastReceiver> --es "referrer" "utm_medium%3Dpartner%26utm_campaign%3Dpartner_name"
注意:引荐来源网址应为url编码。
找到了一个不错的开源工具,该工具可让您扫描在此处生成的引荐qrcode ,并发送包含所有正确信息的广播意图。
在AndroidManifest.xml中的包名称与build.gradle中的applicationId匹配的情况下,pjv的答案有效。如果不匹配,请执行以下操作:
给定:
applicationId是com.my.app.debug
程序包是com.package.app
接收者,path.to.MyReceiver
然后将广播到com.my.app.debug/com.package.app.path.to.MyReceiver
此处的详细信息:https : //groups.google.com/forum/#!topic/adt-dev/PjTHX79Iomw
https://github.com/rogerbinns/referraltester这是一个很棒的应用程序,用于启动“ com.android.vending.INSTALL_REFERRER”广播。您也可以输入参数。
Goople Play收到一个APP链接,并要求用户单击下载,而Google Play在下载完成后会发送广播。APP链接通常会带有一些参数(例如以下示例),以使Google Play和APP知道来源。
Https://play.google.com/store/apps/details?id=com.example.application
& Referrer = utm_source% 3Dgoogle
% 26utm_medium% 3Dcpc
% 26utm_term% 3Drunning% 252Bshoes
% 26utm_content% 3Dlogolink
% 26utm_campaign% 3Dspring_sale
因此,我们可以使用adb模拟来自Google Play的广播。
echo 'am broadcast \
-a com.android.vending.INSTALL_REFERRER \
-n "com.google.samples.quickstart.analytics/com.google.android.gms.analytics.CampaignTrackingReceiver" \
--es "referrer" \
"utm_source=test_sourceCampaignTrackingReceiver&utm_medium=referral&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"; \
exit' | adb shell