问题描述
|
您好,我如何创建永久通知(如第一个电池指示器通知)?
解决方法
将“ 0”标志分配给您的“ 1”。
样例代码:
yourNotification.flags = Notification.FLAG_ONGOING_EVENT;
// Notify...
如果您不熟悉Notification
API,请阅读Android开发者网站上的创建状态栏通知。
,如果您使用NotificationCompat.Builder
,则可以使用:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
mBuilder.setOngoing(true); //this will make ongoing notification
,实际上,建议按位或通知标志,而不是直接设置标志。这使您可以一次设置多个标志。
例如:
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
将同时设置两个标志,而:
notification.flags = Notification.FLAG_ONGOING_EVENT;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
只会设置FLAG_SHOW_LIGHTS标志。
,public static final int FLAG_ONGOING_EVENT
由于:API级别1
如果此通知引用的是正在进行的操作(例如电话),则应按位或按位进入应该设置的标志字段。
public static final int FLAG_FOREGROUND_SERVICE
由于:API级别5
如果此通知表示当前正在运行的服务,则应按位或按位进入应该设置的标志字段。