Android – 在通知栏中保持通知稳定

我已经写了通知栏显示功能
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,notificationIntent,0);

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

它的工作正常,但是即使用户通知栏中的“清除”通知按钮,我们还能以什么方式将通知保持在通知栏

请查看“雅虎”应用程序的通知栏.

我已经通过这个SDK文章http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating,但没有找到.

解决方法

使用FLAG_NO_CLEAR

只需将其设置在通知实例上,然后再将其提供给notificationmanager

notificaton.flags |= Notification.FLAG_NO_CLEAR;

编辑:我只是注意到,如果你使用Notification.Builder(自Honeycomb以来),并且通知正在进行”,它也将免于“清除所有”.见here.

显然,这应该是阻止开发人员使用FLAG_NO_CLEAR进行非正常的通知,因为这可能会混淆用户.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...