1

I am developing an app which contain list of app ,what I have to do is when user click on particular app from list he will be redirected to google play store and download that app after that if success download show a toast and if not then show error toast message in my app .To archeive this I have used Intent with callback but I dont know how to make call back .Kindly help me.

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);
1
  • No way to get application installation successful callback. One trick you can try, use startAtivityForResult and override the onActivityResult method, in onActivityResult method check particular package is installed in device or not, using ActivityInfo. Commented Apr 22, 2016 at 4:06

2 Answers 2

1

You can use startActivityForResult method

try 
{
  Intent viewIntent = new Intent("android.intent.action.VIEW",
  Uri.parse("https://play.google.com/store/apps/details?id=your.app.id.here"));
  startActivityForResult(viewIntent, 1);
}
catch(Exception e) 
{
  Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...",Toast.LENGTH_LONG).show();
  e.printStackTrace();
}

Use onActivityresult method to get result

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) 
{
   super.onActivityResult(requestCode, resultCode, data);
   switch (requestCode) {
        case (1):
            if (resultCode == Activity.RESULT_OK) 
            {
               //Do your stuff here
            }
}
0

You'll want to use

market://details?id=<package_name>

Rather than

http://play.google.com/store/apps/details?id=<package_name>

As a url linking to an app.

1
  • how to make callback
    – niraj
    Commented Apr 22, 2016 at 3:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.