3

is there any possible way to open some specific activity/page after I installed my apps from play store, the url of play store come from deeplink (on the case, the deeplink/url come from QR Code) ?

i am expecting that user will be directed to specific page based on the deeplink

gilllsss
  • 97
  • 2
  • 11
  • You can handle this problem in `Manifest` file or you can add some SplashActivity where you will point out different cases and show to user necessary activity. – Asset Bekbossynov Mar 27 '19 at 04:19
  • Firebase Dynamic Links is the thing you are looking for. https://firebase.google.com/docs/dynamic-links/ – Ranjan Mar 27 '19 at 04:28
  • There are many article provided for deep-linking in android. Find some below:- https://medium.com/@muratcanbur/intro-to-deep-linking-on-android-1b9fe9e38abd https://developer.android.com/training/app-links/deep-linking You can directly come to some page, if you provide proper 'host', 'scheme' and 'path-prefix' – Jatin Mar 27 '19 at 04:33

3 Answers3

2

In 2020, this is the way to do it. You'll need to pass what you need to as part of the referral URL. The code below uses SharedPreferences to store a flag so it'll only process the referral URL once.

in your build.gradle file

dependencies {
    ....
    implementation 'com.android.installreferrer:installreferrer:2.1'
}

And in your AndroidApplication

import android.content.SharedPreferences;
import android.os.RemoteException;
import com.android.installreferrer.api.InstallReferrerClient;
import com.android.installreferrer.api.InstallReferrerStateListener;
import com.android.installreferrer.api.ReferrerDetails;
import com.badlogic.gdx.backends.android.AndroidApplication;

public class YourApplication extends AndroidApplication {

    public static final String REFERRAL_PROCESSED = "referral-processed";

    private void checkInstallReferralLink() {
        final SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(this);
        if (prefs.getBoolean(REFERRAL_PROCESSED, false))
            return;

        final InstallReferrerClient referrerClient;

        referrerClient = InstallReferrerClient.newBuilder(this).build();
        referrerClient.startConnection(new InstallReferrerStateListener() {
            @Override
            public void onInstallReferrerSetupFinished(int responseCode) {
                switch (responseCode) {
                    case InstallReferrerClient.InstallReferrerResponse.OK:
                        ReferrerDetails response;
                        try {
                            response = referrerClient.getInstallReferrer();
                            if (response != null) {
                                String referrerUrl = response.getInstallReferrer();
                                if (referrerUrl != null) {
                                    processReferralUrl(referrerUrl);
                                }
                            }

                            SharedPreferences.Editor editor = prefs.edit();
                            editor.putBoolean(REFERRAL_PROCESSED, true);
                            editor.apply();
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
                        break;
                    case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                    case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                    case InstallReferrerClient.InstallReferrerResponse.DEVELOPER_ERROR:
                    case InstallReferrerClient.InstallReferrerResponse.SERVICE_DISCONNECTED:
                        break;
                }
            }

            @Override
            public void onInstallReferrerServiceDisconnected() {
            }
        });
    }

    private void processReferralUrl(String referrerUrl) {
        // Do what you need to here
    }
}
Will Calderwood
  • 4,393
  • 3
  • 39
  • 64
1

To open the specific screen using Deep link, you need to implement the deeplink functionality and add specific screen in Manifest file. Please refer the below sample to implement the deeplink:

https://medium.com/@muratcanbur/intro-to-deep-linking-on-android-1b9fe9e38abd

Google
  • 2,183
  • 3
  • 27
  • 48
  • what if the user not download app yet, how to identify the deeplink and direct user to some spesific page after they download the app ? – gilllsss Mar 27 '19 at 06:26
  • can you please tell what actually want? i can not understand – Google Mar 28 '19 at 09:34
  • let said , i have a url to my application on playstore, when user download and installed it, it will be direct the user to spesific page. how to do so ? – gilllsss Mar 28 '19 at 10:21
0

You need to declare receiver with intent filter that contains

<action android:name="com.android.vending.INSTALL_REFERRER" />

then get data from intent by key "referrer"

@Override
public void onReceive(Context context, Intent intent) {
    String rawReferrerString = intent.getStringExtra("referrer");
    if(rawReferrerString != null) {
        Log.i("MyApp", "Received the following intent " + rawReferrerString);
    }
}

https://developer.android.com/google/play/installreferrer

Alexandr
  • 1
  • 1