1

How to launch an app from a package name? I have tried this:

     try {
            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
        } catch (ActivityNotFoundException e) { context.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + packageName)));
        }

but I get the exception:

 Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

How do I fix this?

  • Possible duplicate of [Calling startActivity() from outside of an Activity context](https://stackoverflow.com/questions/3918517/calling-startactivity-from-outside-of-an-activity-context) – TheWanderer Dec 04 '18 at 16:12

1 Answers1

0

You have to use intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if you are calling an activity outside of the another activity. Additionally, you shouldn't make same thing in catch block.

melianor
  • 170
  • 2
  • 10