【问题标题】:Opening browser on notification click is not working on MI phones点击通知时打开浏览器不适用于 MI 手机
【发布时间】:2018-02-23 06:37:45
【问题描述】:

在小米手机中,当我尝试使用以下代码通过点击通知重定向到浏览器时:

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            try {
                context.startActivity(intent);
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, e.getMessage());
            }

重定向不起作用,它抛出一个错误“从 Activity 上下文之外调用 startActivity() 需要
FLAG_ACTIVITY_NEW_TASK 标志。这真的是你想要的吗?”。

我是

在其他手机上运行良好。谁能帮忙解决这个问题?

【问题讨论】:

    标签: android android-intent push-notification android-notifications


    【解决方案1】:

    当您从活动类中调用 startActivity 时会发生这种情况。使用以下代码解决您的问题,它将起作用。供参考,你可以看到

    FLAG_ACTIVITY_NEW_TASK clarification needed

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
     intent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    context.startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    Log.e(TAG, e.getMessage());
                }
    

    【讨论】:

    • 但在其他手机上也可以使用。该标志仅在 MI 手机中需要。
    • 不只是 MI 手机,它也发生在其他手机上,我在三星 Galaxy S5 上也遇到过这个问题。您可以添加上面的代码,它将适用于所有设备。
    • 但是如果我想在我的应用中使用深层链接进行特定活动怎么办?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-14
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 2020-05-05
    • 1970-01-01
    相关资源
    最近更新 更多