Android 锁屏通知无法双击打开浏览器 [英] Android lock screen notification is not able to open Browser on double tapping

查看:39
本文介绍了Android 锁屏通知无法双击打开浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序发出一个通知,它会在点击时使用给定的 url 打开浏览器.实际上,包装好的意图被发送到一个 BroadcastReceiver,这个广播接收器启动 Browser.

My app sends out a notification, which opens the Browser with the given url on tapping. Actually, the wrapped intent is sent to a BroadcastReceiver, and this broadcast receiver starts Browser.

Intent browserIntent = new Intent(Intent.ACTION_VIEW, intent.getData());
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(showTaskIntent);

它适用于下拉通知栏上的通知,但不适用于锁屏通知.双击无法打开浏览器.

It works fine with the notification on pull-down notification bar, but not with the lock screen notification. It's not able to open Browser on double tapping.

从日志中可以看到ActivityManager收到了intent,并尝试启动Broswer:

From the log, I can see ActivityManager receives the intent, and tries to start Broswer:

09-02 15:10:52.309 1536-1894/system_process I/ActivityManager: START u0 {act=android.intent.action.VIEW dat=https://www.thesun.co.uk/... flg=0x10000000 cmp=com.android.browser/.BrowserActivity} 来自 uid 10059 on display 0

09-02 15:10:52.309 1536-1894/system_process I/ActivityManager: START u0 {act=android.intent.action.VIEW dat=https://www.thesun.co.uk/... flg=0x10000000 cmp=com.android.browser/.BrowserActivity} from uid 10059 on display 0

但是浏览器发生了什么

09-02 15:10:52.910 12131-12131/com.android.browser I/art:启动阻塞 GC 显式09-02 15:10:52.978 12131-12131/com.android.browser I/art:显式并发标记扫描 GC 释放 44(1768B)个 AllocSpace 对象,0(0B)个 LOS 对象,15% 空闲,11MB/13MB,暂停427us 总共 63.223ms09-02 15:10:52.980 12131-12131/com.android.browser I/art:启动阻塞 GC 显式09-02 15:10:53.095 12131-12131/com.android.browser I/art:显式并发标记扫描 GC 释放 5(160B) 个 AllocSpace 对象,0(0B) 个 LOS 对象,15% 空闲,11MB/13MB,暂停697us 总计 114.607ms09-02 15:10:53.095 12131-12131/com.android.browser I/art:启动阻塞 GC 显式09-02 15:10:53.255 12131-12131/com.android.browser I/art:显式并发标记扫描 GC 释放了 3(96B) 个 AllocSpace 对象,0(0B) 个 LOS 对象,15% 空闲,11MB/13MB,暂停42.926ms 总共 145.640ms

09-02 15:10:52.910 12131-12131/com.android.browser I/art: Starting a blocking GC Explicit 09-02 15:10:52.978 12131-12131/com.android.browser I/art: Explicit concurrent mark sweep GC freed 44(1768B) AllocSpace objects, 0(0B) LOS objects, 15% free, 11MB/13MB, paused 427us total 63.223ms 09-02 15:10:52.980 12131-12131/com.android.browser I/art: Starting a blocking GC Explicit 09-02 15:10:53.095 12131-12131/com.android.browser I/art: Explicit concurrent mark sweep GC freed 5(160B) AllocSpace objects, 0(0B) LOS objects, 15% free, 11MB/13MB, paused 697us total 114.607ms 09-02 15:10:53.095 12131-12131/com.android.browser I/art: Starting a blocking GC Explicit 09-02 15:10:53.255 12131-12131/com.android.browser I/art: Explicit concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 15% free, 11MB/13MB, paused 42.926ms total 145.640ms

我的假设是:当时设备还处于锁屏状态,当ActivityManager下发启动浏览器的意图时,Android系统可能有一些检查或机制不启动该Activity.

My assumption is: at that time, the device is still locked by lock screen, when ActivityManager delivers the intent to start Browser, the Android system might have some checks or mechanism not to start that activity.

有没有人遇到过这样的问题?谢谢!

Has anyone had such a problem before? Thanks!

推荐答案

我认为这是 Chrome 中的一个错误,我已经向 Android 和 Chrome 提出了这个问题:

I think this is a bug in Chrome, and I have raised this issue to both Android and Chrome:

https://code.google.com/p/android/issues/detail?id=221940&can=4&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20开

https://bugs.chromium.org/p/chromium/issues/detail?id=645848&can=4&q=&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified

但是,我找到了一个解决方法:使用自定义标签而不是普通标签可以解决这个问题.

However, I found a workaround: Use custom tabs instead of normal tabs can solve this issue.

intent.putExtra("android.support.customtabs.extra.SESSION", context.getPackageName());
intent.putExtra("android.support.customtabs.extra.EXTRA_ENABLE_INSTANT_APPS", true);

添加上面的 Extras 以强制 Chrome 使用自定义标签.

Add above Extras to force Chrome to use custom tabs.

在此处查找更多信息:https://developer.chrome.com/multidevice/android/customtabs

这篇关于Android 锁屏通知无法双击打开浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆