我需要在我的应用中集成引用代码实现,因为我创建了url: https://play.google.com/store/apps/detailsid=MY_PACKAGE_NAME&referrer=USER_REFERRAL_CODE
并为此创建广播接收器
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);
}
}
}
<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商店安装应用程序后有我的接收器调用,但我在推荐代码
中获得空值我需要获取将app引用给其他用户的用户代码。但要做到这一点,我会失败。我也使用shell脚本在终端中测试我的接收器,它对我来说很好。
因此,如果此代码存在任何问题,请告诉我这样做或建议我采用另一种方法来执行此操作。谢谢......
答案 0 :(得分:2)
验证您正在测试的Play商店网址是否正确并且具有测试的预期值。遵循定义为:
的方案 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();
}
有关详细信息,请查看https://developers.google.com/analytics/devguides/collection/android/v4/campaigns上的文档。
例如进行推荐:
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;
}
}
然后在你的接收器中:
{{1}}