簡體   English   中英

在通知點擊上打開瀏覽器在MI手機上不起作用

[英]Opening browser on notification click is not working on MI phones

在小米手機中,當我嘗試使用以下代碼單擊通知時重定向到瀏覽器時:

 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標志。 這真的是您想要的嗎?”。

我是

在其他手機上也可以正常工作。 誰能幫助解決這個問題?

當您在活動類中調用startActivity時,就會發生這種情況。 使用下面的代碼來解決您的問題,它將起作用。 供參考,你可以看到

需要澄清FLAG_ACTIVITY_NEW_TASK

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());
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM