dependencies { ... compile 'com.android.installreferrer:installreferrer:1.0' }
InstallReferrerStateListener
public class MainActivity extends AppCompatActivity implements InstallReferrerStateListener { … }
InstallReferrerClient
startConnection()
InstallReferrerClient mReferrerClient ... mReferrerClient = newBuilder(this).build(); mReferrerClient.startConnection(this);
onInstallReferrerSetupFinished()
getInstallReferrer()
@Override public void onInstallReferrerSetupFinished(int responseCode) { switch (responseCode) { case InstallReferrerResponse.OK: try { Log.v(TAG, "InstallReferrer conneceted"); ReferrerDetails response = mReferrerClient.getInstallReferrer(); handleReferrer(response); 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."); } }
IGetInstallReferrerService AIDL reference