最近开发app,做了一个闹钟通知,到时间时,用notificaton在手机顶部弹出一
个通知(只能通过点击通知或上划通知取消),并发出铃声。因为通知设置了
setAutoCancel以点击通知后,通知是会自动消失的(状态栏和下拉列表都没
有了 此通知)。但是如果不点击而是上划通知的话,铃声和弹出的通知会消失
但是状态栏还是会有通知的图标,而且下拉列表也会有这个通知。有没有大神
知道如何在上划通知是,彻底把通知cancel了。我的代码如下:
NotificationManager notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent intent=new Intent(this,AlarmActivity.class);
PendingIntent pi=PendingIntent.getActivity(this,0,intent,0);
Notification notification=new NotificationCompat.Builder(this,"alarm")
.setSmallIcon(R.mipmap.ic_launcher_round)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher_round))
.setContentTitle("闹钟")
.setContentText("id="+alarmID)
.setSound(Uri.parse("android.resource://"+getApplicationContext().getPackageName()+
"/"+R.raw.bell))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSound(Uri.parse("android.resource://"+getApplicationContext().getPackageName()+
"/"+R.raw.bell))
.setContentIntent(pi)//点击结束响铃并且跳到闹钟列表页面,且页面更新
//.setAutoCancel(true)//点击通知后,通知自动消失,无效
.build();
notification.flags=Notification.FLAG_INSISTENT|Notification.FLAG_AUTO_CANCEL;//将重复音频,直到取消通知或打开通知窗口
notification.fullScreenIntent=pi;
notificationManager.notify(alarmID,notification);```