Java 隐藏正在进行的通知
我有以下代码来创建一个Java 隐藏正在进行的通知,java,android,Java,Android,我有以下代码来创建一个正在进行的\u事件: Notification notification = new Notification(R.drawable.icon, "someText" , System.currentTimeMillis()); notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_FOREGROUND_SERVICE; PendingI
正在进行的\u事件
:
Notification notification = new Notification(R.drawable.icon, "someText" , System.currentTimeMillis());
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Home.class), 0);
notification.setLatestEventInfo(this, "someTitle", "someText", contentIntent);
notificationManager.notify(SOME_ID, notification);
现在,我想稍后杀死它:
notificationManager.cancel(SOME_ID);
然而,通知仍然有效。这可能是什么原因造成的?我尚未实现此标志,但请检查通知标志。在创建通知之前添加此标记。我尚未实现此标记,但请检查通知标记。在创建通知之前添加此选项。问题是
notification.flags |=notification.FLAG|u前台_服务代码>。我误解了此标志的文档,随后无法删除通知。该标志通常由以startForeground(int-id,Notification Notification)
启动的服务设置,并防止删除通知,直到服务被stopfrogent(boolean removeNotification)
停止
我现在使用了startForeground
/stopfrogent
方法,通知显示/隐藏得非常好。问题是notification.flags |=notification.FLAG_front_服务代码>。我误解了此标志的文档,随后无法删除通知。该标志通常由以startForeground(int-id,Notification Notification)
启动的服务设置,并防止删除通知,直到服务被stopfrogent(boolean removeNotification)
停止
我现在使用startForeground
/stopForeground
方法,通知显示/隐藏得非常好。这将在用户单击时取消通知,而不是我想要实现的,因为通知详细说明了上载。这将在用户单击时取消通知,这不是我想要实现的,因为通知详细说明了上传。这可能对你的姿势有帮助。这可能对你的姿势有帮助。