从应用商店安装android应用后无法获取引荐代码

时间:2019-05-28 04:37:33

标签: android google-play google-play-services

在我的应用程序中有一个推荐程序。我希望当客户共享应用程序链接时,该链接重定向到playstore,并在安装应用程序后从playstore检索推荐代码。我已经做了该链接,但是我不明白在安装后如何接收该推荐代码。

<div class="col-lg-4">
<div class="col-lg-12">
 your content 1
</div>
</div>

<div class="col-lg-4">
<div class="col-lg-12">
your content 2
</div>
</div>

<div class="col-lg-4">
<div class="col-lg-12">
your content 3
</div>
</div>

2 个答案:

答案 0 :(得分:1)

为此,您必须在库下面使用

实现'com.android.installreferrer:installreferrer:1.0'

https://developer.android.com/google/play/installreferrer/library

https://developer.android.com/training/app-links/deep-linking.html

谢谢,它可能对您有帮助

答案 1 :(得分:1)

使用引荐代码创建链接并发送给其他朋友和用户...

String link = http://yourdomain.com/testrefer.php?refercode=ABCD // http or https

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, link);
context.startActivity(Intent.createChooser(sharingIntent, "Share Via"));

并在testrefer文件中创建应用商店链接并添加引荐代码,然后使用下面的链接重定向到Play商店,然后您可以获得引荐代码。

https://play.google.com/store/apps/details?id="+context.getPackageName()+"&referrer=ABCD

在启动屏幕的Manifest文件中

编写以下代码

<activity
    android:name=".activity.SplActivity"
    android:screenOrientation="portrait"
    android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:host="yourdomain.com"
                android:pathPrefix="/testrefer.php"
                android:scheme="https" />  <!-- https or http -->
      </intent-filter>
</activity>

InstallRefererReciever是您创建的BroadcastReceiver文件名

<receiver
    android:name=".common.InstallRefererReciever" 
    android:exported="true"
    android:permission="android.permission.INSTALL_PACKAGES">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

创建BroascatReceiver并编写以下代码:

public class InstallRefererReciever extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
          Bundle extras = intent.getExtras();
          if (extras != null) {
             String referral = extras.getString("referrer");
             Logger.e("ReferCode --> ", referral);
             if (referral != null) {
                 if (!referral.equals("utm_source=google-play&utm_medium=organic")) {
                     if (!referral.equals("com.android.chrome")) {
                       String referralCode = referral; // Store in sharedpreferences
                    }
                }
             }
          }
       }
   }


}
相关问题