4

我使用 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);
4

2 回答 2

9

替换setAutoCancel(true)setOngoing(true)

于 2013-06-23T00:38:31.050 回答
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);
于 2013-06-23T00:39:07.277 回答