Android lock screen notification is not able to op

2019-01-25 22:39发布

问题:

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.

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} from uid 10059 on display 0

But what happened to Browser is

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

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!

回答1:

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%20Opened

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

Add above Extras to force Chrome to use custom tabs.

Find more here: https://developer.chrome.com/multidevice/android/customtabs