Reputation: 97
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
Upvotes: 3
Views: 3302
Reputation: 4636
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
}
}
Upvotes: 2
Reputation: 1
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
Upvotes: 0
Reputation: 2223
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
Upvotes: 1