2

How to open google play store using intent with callback in android .

here is my code:-

Uri uri = Uri.parse("https://play.google.com");// sending to Deal Website
            Intent i = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(i);
rahul
  • 211
  • 1
  • 3
  • 9

1 Answers1

2

This code works if user go back after install or discard the app on market. I hope it helps you.

String appPackageName = "com.application.package";

void methodThatLaunchesGooglePlay(){
    try {
       startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)), YOUR_REQUEST_CODE);
    } catch (android.content.ActivityNotFoundException anfe) {
       startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)), YOUR_REQUEST_CODE);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == YOUR_REQUEST_CODE){
        try{
            getPackageManager().getPackageInfo(appPackageName, PackageManager.GET_ACTIVITIES);
            //App Installed
        } catch (PackageManager.NameNotFoundException e) {
            //App doesn't installed
        }
    }
}
Julio Gómez
  • 330
  • 7
  • 18