Android的 - 保持稳定的通知在通知栏 [英] Android - Keep notification steady at Notification Bar

查看:389
本文介绍了Android的 - 保持稳定的通知在通知栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了函数通知并显示在通知栏:

I have written the function to notify and display at Notification bar:

private void showNotification()
    {
            CharSequence title = "Hello";
            CharSequence message = "Notification Demo";

            NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
            Notification notification = new Notification(R.drawable.icon, "A Notification", System.currentTimeMillis());
            Intent notificationIntent = new Intent(this, Main_Activity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

            notification.setLatestEventInfo(Main_Activity.this, title, message, pendingIntent);
            notificationManager.notify(NOTIFICATION_ID, notification);
    }

其工作正常,但 什么样的​​方式,我们可以保持通知稳定在通知栏 ,即使用户preSS的清 notificatios从通知栏按钮?

Its working fine, But what way we can keep the notification steady at Notification bar even when user press the "clear" notificatios button from the notification bar ?

请看看雅虎应用程序的通知吧。

Please have a look at the "Yahoo" application's notification bar.

我已经通过这个SDK文章了:<一href="http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating">http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating ,但未能找到。

I have gone through this SDK article: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating , but failed to find out.

推荐答案

使用 FLAG_NO_CLEAR

其提供给前刚刚把它放在你的通知实例 NotificationManager

Just set it on your Notification instance before supplying it to the NotificationManager:

notificaton.flags |= Notification.FLAG_NO_CLEAR;

编辑:的我只注意到的是,如果您使用的是 Notification.Builder (自蜂窝),并通知正在进行,它也将成为免疫全部清除。请参阅<一href="http://developer.android.com/reference/android/app/Notification.Builder.html#setOngoing%28boolean%29">here.

edit: I just noticed though that if you are using Notification.Builder (since Honeycomb) and make the notification "ongoing", it will also become immune to "clear all". See here.

Appearently,这应该从使用 FLAG_NO_CLEAR 在非持续notificaton因为这可能会混淆用户打消开发者。

Appearently, this is supposed to discourage developers from using the FLAG_NO_CLEAR on a non-ongoing notificaton since this could confuse the user.

这篇关于Android的 - 保持稳定的通知在通知栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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