双击时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收到了该意图,并尝试启动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 =
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.223ms 09-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.607ms 09-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系统可能有一些检查或机制无法启动该活动.
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:
但是,我找到了一种解决方法:使用自定义标签而不是普通标签可以解决此问题.
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);
在其他功能上方添加以强制Chrome使用自定义标签.
Add above Extras to force Chrome to use custom tabs.
在此处查找更多信息: https://developer.chrome.com/multidevice/android/customtabs
Find more here: https://developer.chrome.com/multidevice/android/customtabs