android - 为什么我无法从包名称启动应用程序

标签 android

如何从包名启动应用程序?我试过这个:

     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/

相关文章:

android - 获取与一个联系人android关联的所有手机号码

java - 如何检查url是否可达

php - Android 本地数据库通过 PHP 转换为 XML 到 mySql。

android - 显示 DialogFragment 会引发 "Can not perform this action after onSaveInstanceState"错误

安卓线程/回调

android - 分享失败,在 api 23 中,只有 whatsapp 失败,从选择器中选择 whatsapp 后,它返回到分享者页面

android - 魅族设备上 Editor.updateCursorPositionMz 出现 NullPointerException

java - Android - 无法在模拟器中执行简单的 cd

android - android中 ListView 为空时如何显示消息

java.lang.NoSuchMethodError : No static method with(Landroid/content/Context;)