0

I am trying to open another application from my application like this inside onclick listner

   Intent intent = new Intent(Mainactivity.this, com.pkg.classname)
   startActivity(intent);

It does not work.

I want to open the app if installed or open in playstore if not installed.

Please help

Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122

1 Answers1

0
Context ctx=this;
try {
    Intent i = ctx.getPackageManager().getLaunchIntentForPackage("com.example.app");
    ctx.startActivity(i);
} catch (Exception e) {
    try {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://market.android.com/details?id=com.example.app")));
    } catch (android.content.ActivityNotFoundException anfe) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.example.app")));
    }
}
Mester Hassan
  • 538
  • 5
  • 10