如何从程序包名称启动应用程序?我已经尝试过了:
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)));
}
但我得到了例外:
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?
我该如何解决?
答案 0 :(得分:0)
您必须使用intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);如果您要调用另一个活动之外的活动。此外,您不应在catch块中做同样的事情。