是的,您的标志看起来非常正确,尽管我不知道您是否甚至需要FLAG_NO_CLEAR
. 我目前有一个创建持续(不可取消)通知的应用程序 - 我只使用FLAG_ONGOING_EVENT
它,它对我来说很好用。我几乎只是从教程中复制了它,然后添加了正在进行的事件标志。这是一些示例代码:
String text = "notification";
Notification notification = new Notification(R.drawable.icon, text,
System.currentTimeMillis());
//launch the activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent().setComponent(ComponentName.unflattenFromString("com.example/com.example.MyActivity")), 0);
// set the label and text...
notification.setLatestEventInfo(this, getText(R.string.notification_label),
text, contentIntent);
notification.flags = Notification.FLAG_ONGOING_EVENT;
// Send the notification.
// We use a string id because it is a unique number. We use it later to cancel.
NotificationManager mNM;
mNM.notify(R.string.notification_label, notification);