Created
January 13, 2020 15:24
-
-
Save alpacas9/4fa3ae93490cfc850543e8d6d32fae5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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