debo.stackoverflow
debo.stackoverflow

Reputation: 983

Redirect to google playstore if necessary app is not present

The question is simple.

Step 1: User is presented a button where he/she can download pdf and then view it.

Step 2:If a pdf viewer app is present it will show a chooser.Otherwise the app will redirect to google play store and will show the pdf viewer category apps to download from.

Step 3: After downloading one of the pdf viewer app,the user will again come back to the app and will then open the chooser and now the user can select the downloaded pdf viewer app

I dont know how to go to play store and then come back.

Thanks for your time.

Upvotes: 0

Views: 252

Answers (1)

Dmitriy
Dmitriy

Reputation: 133

use this code for send user to play store

activity.startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri
       .parse("https://play.google.com/store/apps/details?id=" + appPackageName)), REQUEST_CODE);

when user close play store, you know in OnActivityResult method.

complete of installation app you can find out with receiver, like this:

new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

        String packageName = intent.getData().getEncodedSchemeSpecificPart();

    }
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addDataScheme("package");
registerReceiver(mBroadcastReceiver, intentFilter);

Upvotes: 3

Related Questions