我使用NotificationCompat.builder创建了通知。但我不能通过它设置标志以使其无法解决。
任何人都可以帮我解决我的问题,我将很感激你。 :)
谢谢:)
noti_intent = new Intent(this, Main.class);
noti_pend = PendingIntent.getActivity(this, noti_id, noti_intent, 0);
noti_manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
noti = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.status_ico)
.setContentTitle("Next alarm is set to ring on")
.setTicker("Alarm is set to ring")
.setContentText(next_date.getText()+" "+next_time.getText())
.setWhen(System.currentTimeMillis())
.setContentIntent(noti_pend)
.setAutoCancel(false);
答案 0 :(得分:7)
将setAutoCancel(true)
替换为setOngoing(true)
。
答案 1 :(得分:4)
尝试在代码中加入.setOngoing(true)
:
noti_intent = new Intent(this, Main.class);
noti_pend = PendingIntent.getActivity(this, noti_id, noti_intent, 0);
noti_manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
noti = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.status_ico)
.setContentTitle("Next alarm is set to ring on")
.setTicker("Alarm is set to ring")
.setContentText(next_date.getText()+" "+next_time.getText())
.setWhen(System.currentTimeMillis())
.setContentIntent(noti_pend)
.setOngoing(true)
.setAutoCancel(false);