Android - Is it possible to get install referrer programmatically

后端 未结 3 1134
刺人心
刺人心 2020-11-27 13:24

I have noticed some Google Play app links in the browser has the referrer= attribute to them, which obviously tells the referrer that sent you to that app\'s pa

3条回答
  •  遥遥无期
    2020-11-27 13:40

    Use Google Play Referrer API (from 20 Nov 2017)

    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.");
       }
    }
    

提交回复
热议问题