Android的 - 保持稳定的通知在通知栏通知、稳定、Android

由网友(北方故事)分享简介:我已经写了函数通知并显示在通知栏:I have written the function to notify and display at Notification bar:private void showNotification(){CharSequence title = "Hello";CharSequen...

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

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文章了: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 (自蜂窝),并通知正在进行,它也将成为免疫全部清除。请参阅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.

阅读全文

相关推荐

最新文章