Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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 – 在通知栏中保持通知稳定全部内容,希望文章能够帮你解决Android – 在通知栏中保持通知稳定所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。