如何燮锁屏preSS通知中的Andr​​oid 5(棒棒堂),但让它在通知区域? [英] How to suppress notification on lock screen in Android 5 (Lollipop) but let it in notification area?

查看:193
本文介绍了如何燮锁屏preSS通知中的Andr​​oid 5(棒棒堂),但让它在通知区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到Android 5.0之后棒棒糖就开始出现持续的自动通知,在锁屏。

After upgrade to Android 5.0 Lollipop it started showing automatically ongoing notification on lock screen.

有时候,用户不希望看到所有的人,使他们都在问开发商怎么让通知中的地位区域,但其隐藏在锁屏。

Sometimes users don't want to see all of them so they are asking developers how to let notification in status area but hide them on lock screen.

只有这样,我发现是强制用户使用屏幕锁定(如手势或PIN)和编程<一href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setVisibility(int)">setVisibility()到<一个href="http://developer.android.com/reference/android/app/Notification.html#VISIBILITY_SECRET">VISIBILITY_SECRET.但不是所有的人想用锁屏。

Only way I found is to force users use screen lock (eg. Gesture or PIN) and programatically setVisibility() to VISIBILITY_SECRET. But not all them want to use screen lock.

有没有标志(或标志组合)说来通知:不要锁定屏幕上可见,但在通知区域中可见

Is there any flag (or combination of flags) saying to notification: don't be visible on Lock screen but be visible in notification area?

推荐答案

由于覆盖这个答案,你可以使用<一个href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.html#VISIBILITY_SECRET"相对=nofollow> VISIBILITY_SECRET 到晚饭preSS锁屏上的通知,当用户有一个安全的键盘锁(不只是轻扫或没有键盘锁),拥有灵敏的通知燮pressed。

Proposal

As covered by this answer, you can use VISIBILITY_SECRET to suppress the notification on the lock screen when the user has a secure keyguard (not just swipe or no keyguard) and has sensitive notifications suppressed.

要支付的情况下,剩下的,你可以通过设置通知的优先级编程方式隐藏在锁屏和状态栏的通知<一href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.html#PRIORITY_MIN"相对=nofollow> PRIORITY_MIN 每当键盘保护 为present然后重置优先每当键盘锁是不存在的。

To cover the rest of the cases, you can programmatically hide the notification from the lock screen and status bar by setting the notification's priority to PRIORITY_MIN whenever the keyguard is present and then reset the priority whenever the keyguard is absent.

使用Android模拟器5,这似乎导致通知很简短地出现在锁屏上,但随后消失。

Using an Android 5 emulator, this seems to result in the notification very briefly appearing on the lock screen but then disappearing.

final BroadcastReceiver notificationUpdateReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        NotificationManager notificationManager =
            (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context);
            .setVisibility(NotificationCompat.VISIBILITY_SECRET);

        KeyguardManager keyguardManager =
            (KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE);

        if (keyguardManager.isKeyguardLocked())
            builder.setPriority(NotificationCompat.PRIORITY_MIN);

        notificationManager.notify(YOUR_NOTIFICATION_ID, notification);
    }
};

//For when the screen might have been locked
context.registerReceiver(notificationUpdateReceiver,
    new IntentFilter(Intent.ACTION_SCREEN_OFF));

//Just in case the screen didn't get a chance to finish turning off but still locked
context.registerReceiver(notificationUpdateReceiver,
    new IntentFilter(Intent.ACTION_SCREEN_ON));

//For when the user unlocks the device
context.registerReceiver(notificationUpdateReceiver,
    new IntentFilter(Intent.ACTION_USER_PRESENT));

//For when the user changes users
context.registerReceiver(notificationUpdateReceiver,
    new IntentFilter(Intent.ACTION_USER_BACKGROUND));
context.registerReceiver(notificationUpdateReceiver,
    new IntentFilter(Intent.ACTION_USER_FOREGROUND));

这篇关于如何燮锁屏preSS通知中的Andr​​oid 5(棒棒堂),但让它在通知区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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