Android通知点击后立即清除
问题描述:
我想创建一个通知,用户无法通过向左或向右拖动来关闭它。 用户必须点击但愿关闭通知Android通知点击后立即清除
我的代码是:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
Notification n = new Notification.Builder(getApplicationContext())
.setContentTitle("title")
.setContentText("text")
.setSmallIcon(R.drawable.ic_tt)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_tt))
.setContentIntent(pIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setOngoing(true).build();
n.flags |= Notification.FLAG_ONGOING_EVENT;
NotificationManager notificationManager =(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
但dosnot工作 什么想法?
答
您需要使用这两种功能保留通知,
nBuilder.setOngoing(true);
nBuilder.setAutoCancel(true);
它只能在用户点击它被取消。 在此Managing Notifications中查找setAutoCancel。 希望这有助于!
根本不显示通知,或者只显示为正常通知? – s3lph 2015-04-03 10:35:49
@the_Seppi通知显示,但不能关闭。 – 2015-04-03 10:38:21
显示为正在进行还是正常? – s3lph 2015-04-03 10:39:30