我需要在我用:CODE创建url的应用程序中集成推荐代码实现。
并为此创建了广播接收器
InstallReferrerReceiver.java
public class InstallReferrerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.android.vending.INSTALL_REFERRER")) {
String referrer = "";
Bundle extras = intent.getExtras();
if (extras != null) {
referrer = extras.getString("referrer");
}
Log.e(TAG, "Referal Code Is: " + referrer);
AppMethod.setStringPreference(context, AppConstant.PREF_REF_ID, referrer);
}
}
}manifest.xml中的寄存器接收机
<receiver
android:name="com.gum.getumoney.Service.InstallReferrerReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>在从play商店安装应用程序后,有我的接收程序调用,但是我在Referral代码中得到了null值
我需要得到的用户代码,谁把应用程序的另一个用户。但这样做我会失败的。此外,我测试我的接收器在终端使用外壳脚本,它的工作对我来说很好。
因此,如果这段代码有任何问题,那么请告诉我这样做的原因,或者建议我采取其他方法。谢谢..。
发布于 2017-08-25 12:45:47
验证您正在测试的play存储库url是否正确,并具有测试的期望值。遵循以下定义的计划:
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有关更多信息,请查看https://developers.google.com/analytics/devguides/collection/android/v4/campaigns上的文档。
例如,要进行推荐:
public void sendReferral(Context context) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, getInvitationMessage()), PreferencesManager.getInstance().getKeyReferrerUrl()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.invitation_subject));
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, context.getResources().getText(R.string.invitation_extended_title)));
}
private String getInvitationMessage(){
String playStoreLink = "https://play.google.com/store/apps/details?id=app.package.com&referrer=utm_source=";
return invitationId = playStoreLink + getReferralId();
}然后在你的接收器里:
public class InstallReferrerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
return;
}
String referrerId = intent.getStringExtra("referrer");
if (referrerId == null){
return;
}
}https://stackoverflow.com/questions/45881614
复制相似问题