如何从包名启动应用程序?我试过这个:
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)));
}
但我得到了异常(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?
我该如何解决这个问题?
最佳答案
你必须使用 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);如果您在另一个 Activity 之外调用一个 Activity 。此外,您不应该在 catch block 中做同样的事情。
关于android - 为什么我无法从包名称启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53617089/