2

I'm developing an android application in Java where I need to pass the referer information to an URL. I'm getting the referrer information using Play Install Referrer Library.

Here is my code:

InstallReferrerClient referrerClient = InstallReferrerClient.newBuilder(this).build();
    referrerClient.startConnection(new InstallReferrerStateListener() {
        @Override
        public void onInstallReferrerSetupFinished(int responseCode) {
            switch (responseCode) {
                case InstallReferrerClient.InstallReferrerResponse.OK:
                    try {
                        Log.v("TAG", "InstallReferrer conneceted");
                        ReferrerDetails response = referrerClient.getInstallReferrer();
                        System.out.println("referrerUrl ID: " + response);
                        referrerClient.endConnection();
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                    break;
                case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                    Log.w("TAG", "InstallReferrer not supported");
                    break;
                case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                    Log.w("TAG", "Unable to connect to the service");
                    break;
                default:
                    Log.w("TAG", "responseCode not found.");
            }
        }

        @Override
        public void onInstallReferrerServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }
    });

Code is working fine and currently, the above snippet is inside my activity's onCreate method. which means it will start the new connection every time the user opens the activity.

In the library documentation, they have written that

Caution: The install referrer information will be available for 90 days and won't change unless the application is reinstalled. To avoid unnecessary API calls in your app, you should invoke the API only once during the first execution after install.

This is where I'm stuck, should I just call this thing when the application starts the first time? If yes, I can store this referrer in the shared preference, but then how will I able to know that 90 days have been passed and I need to trigger that action again? Or it there something else that should I need to implement? Kindly help me with this issue.

Jay Patel
  • 2,341
  • 2
  • 22
  • 43

0 Answers0