这个api可以获取从play store下载的来源渠道,这里可以自定义,例如 邀请功能等就很好使用了。
测试的时候,可以上传包到封闭式测试,然后点链接再下载包打开
配合play的地址 添加referrer 字段 例如
https://play.google.com/store/apps/details?id=包名&referrer=自定义数据
然后再安卓端获取
ReferrerDetails response = referrerClient.getInstallReferrer();
String content=response.getInstallReferrer();
final InstallReferrerClient referrerClient = InstallReferrerClient.newBuilder(context).build();
referrerClient.startConnection(new InstallReferrerStateListener() {
@Override
public void onInstallReferrerSetupFinished(int responseCode) {
GHLog.log("---onInstallReferrerSetupFinished----"+responseCode);
switch (responseCode) {
case InstallReferrerClient.InstallReferrerResponse.OK:
// Connection established.
try {
ReferrerDetails response = referrerClient.getInstallReferrer();
String content=response.getInstallReferrer();
GHLog.log("getInstallReferrer:"+content);
} catch (Exception e) {
e.printStackTrace();
GHLog.log("-----RemoteException-----"+e.getMessage());
}
break;
case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
// API not available on the current Play Store app.
break;
case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
// Connection couldn't be established.
break;
}
}
@Override
public void onInstallReferrerServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
GHLog.log("-----onInstallReferrerServiceDisconnected---");
}
});