Android 通知赢得';“不必”;“正在进行”;

Android 通知赢得';“不必”;“正在进行”;,android,notifications,Android,Notifications,我想显示一个正在进行的通知。但它仍然显示在通知部分。 我在通知中使用了自定义布局 这是我的密码: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); NotificationManager mNotificationManager = (NotificationMan

我想显示一个正在进行的通知。但它仍然显示在通知部分。 我在通知中使用了自定义布局

这是我的密码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = android.R.drawable.alert_dark_frame;
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, "Hi", when);
    RemoteViews contentView = new RemoteViews(getPackageName(),
            R.layout.custom_notification);
    notification.contentView = contentView;

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);

    notification.contentIntent = contentIntent;
    notification.defaults |= Notification.FLAG_ONGOING_EVENT;
    mNotificationManager.notify(0, notification);
}
编辑: 你可以看到这张图片,看看我想做什么。

除了
NotificationManager.notify()


编辑:我还建议您使用Notification.Builder而不是new Notification(),然后使用,只是为了保持其整洁。

标记为“正在进行的事件”的通知仍然是通知。这就是它出现在通知列表中的原因。它基本上是一个粘性通知,不能用清除按钮从列表中清除。你说“但它仍然显示在通知部分”是什么意思。难道你不希望它显示在那里吗?@NobuGames我想那是通知。FLAG_NO_CLEAR使通知不可清除。@PatrickKafka我将添加一张照片来澄清我的问题。@NimaAhmadi我已更正,很抱歉混淆!谢谢我想在考虑通知之前,我需要为我的应用程序提供服务。我将支持低至API级别8,但那里不支持notification builder@如果你想支持8级API,你可以使用Android兼容性库