Android - 是否可以通过编程方式获得安装引荐来源

时间:2015-05-07 13:59:31

标签: android google-play

我注意到浏览器中的某些Google Play应用链接具有namespace CirclesApplication { public class Circle {//the rest of the class } } 属性,这显然告诉推荐人将您发送到Google Play中该应用的页面。

是否可以在我的应用代码中看到引荐来源(如果有的话)?如果没有,那么在任何地方都可以看到它?

2 个答案:

答案 0 :(得分:50)

您可以使用com.android.vending.INSTALL_REFERRER

  

Google Play com.android.vending.INSTALL_REFERRER意图是   从Google Play商店安装应用时广播。

将此接收器添加到AndroidManifest.xml

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

创建BroadcastReceiver:

public class InstallReferrerReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String referrer = intent.getStringExtra("referrer");

        //Use the referrer
    }
}

您可以按照此answer的步骤测试引荐跟踪。

答案 1 :(得分:3)

使用Google Play Referrer API(2017年11月20日起)

InstallReferrerClient mReferrerClient
...
mReferrerClient = newBuilder(this).build();
mReferrerClient.startConnection(this);

@Override
public void onInstallReferrerSetupFinished(int responseCode) {
   switch (responseCode) {
       case InstallReferrerResponse.OK:
           try {
               ReferrerDetails response = mReferrerClient.getInstallReferrer();
               String referrer = response.getInstallReferrer()
               mReferrerClient.endConnection();
           } catch (RemoteException e) {
               e.printStackTrace();
           }
           break;
       case InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
           Log.w(TAG, "InstallReferrer not supported");
           break;
       case InstallReferrerResponse.SERVICE_UNAVAILABLE:
           Log.w(TAG, "Unable to connect to the service");
           break;
       default:
           Log.w(TAG, "responseCode not found.");
   }
}