-1

I'm trying to open another app from my app . if that app is not installed my code will open the market place. i use this code

PackageManager pm = getPackageManager();
try
{               
 Intent intent = pm.getLaunchIntentForPackage(package_name);
 startActivity(intent);
}    
catch(android.content.ActivityNotFoundException anfe)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + package_name)));
}

if market is not presence in the device i should open http://play.google.com/store/apps/details?id=<package_name> this url. how to catch the exception at second time? i have already used catch in my code ! can i one more? i'm new for OOP.

Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71

2 Answers2

1
try{
Intent intent = pm.getLaunchIntentForPackage(package_name);
startActivity(intent);
}
catch(Exception anfe)
{
        try{
             startActivity(new Intent(Intent.ACTION_VIEW,    Uri.parse("market://details?id=" + package_name)));
         }
        catch(Exception a){
        {
          startActivity(new Intent(Intent.ACTION_VIEW,    
          Uri.parse("https://play.google.com/store/apps/details?id=" + package_name)));
        }
    }
-1

You can use

    try { 
//YOUR CODE
} catch( IOException | IOException2 ex) { 
  logger.log(ex);
  throw ex;
}

Or also you can do by this way

    try
{ 
    // YOUR CODE
}
catch (IOException example)
{
    // whateveryouwant
}
catch (Exception example)
{
   // whateveryouwant
}

The thing is that you have to know what is the exception.

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148