Skip to content

Instantly share code, notes, and snippets.

@alpacas9
Created January 13, 2020 15:24
Show Gist options
  • Select an option

  • Save alpacas9/4fa3ae93490cfc850543e8d6d32fae5f to your computer and use it in GitHub Desktop.

Select an option

Save alpacas9/4fa3ae93490cfc850543e8d6d32fae5f to your computer and use it in GitHub Desktop.
// add dependency to gradle
implementation 'com.android.installreferrer:installreferrer:1.1'
// add variable inside Activity/Class
InstallReferrerClient referrerClient;
// call this code
referrerClient = InstallReferrerClient.newBuilder(this).build();
referrerClient.startConnection(new InstallReferrerStateListener() {
@Override
public void onInstallReferrerSetupFinished(int responseCode) {
switch (responseCode) {
case InstallReferrerClient.InstallReferrerResponse.OK:
// Connection established.
ReferrerDetails response = null;
try {
response = referrerClient.getInstallReferrer();
} catch (RemoteException e) {
e.printStackTrace();
}
// THIS IS WHAT WE NEED. Pass this string to our tracker
String referrerUrl = response.getInstallReferrer();
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.
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment