从 Play 商店安装后无法检索推荐代码

Referral Code not retrieve after installing from play store

我需要在我创建的 url 应用中集成推荐代码实现: https://play.google.com/store/apps/detailsid=MY_PACKAGE_NAME&referrer=USER_REFERRAL_CODE

并为此创建了广播接收器

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 商店安装应用程序后有我的接听电话,但我在推荐代码中得到空值

我需要获取将应用推荐给其他用户的用户代码。但是这样做我会失败。我还使用 shell 脚本在终端中测试了我的接收器,它对我来说工作正常。

因此,如果此代码有任何问题,请告诉我这样做或建议我另一种方法来执行此操作。谢谢...

验证您正在测试的 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;
        }
}