如何设置我的通知以便在点击时自行清除?
我已设置autoCancel(true)
但不起作用
我的代码:
Notification n = new Notification.Builder(this)
.setContentTitle("Update for you")
.setContentText("Please click here to see the update information")
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
R.drawable.ic_launcher))
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pList)
.setAutoCancel(true)
.addAction(R.drawable.ic_read, "Read", pRead)
.addAction(R.drawable.ic_list, "All Updates", pList)
.build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
答案 0 :(得分:3)
setAutoCancel()
的{{1}}。也许,您的最低版本低于API 11.
Notification.Builder
也可在setAutoCancel()
类中使用,该类已添加到支持库
NotificationCompat.Builder
答案 1 :(得分:1)
n.flags |= Notification.FLAG_AUTO_CANCEL;
答案 2 :(得分:1)
<强> SetAutoCancel(真)强>
func sectionForDegrees(degree: CGFloat){
var result = "not defined"
switch degree{
case 0.1 ... 90:
result = "1 \(degree)"
case 90.1...180:
result = "4 \(degree)"
case -90.1...0:
result = "2 \(degree)"
case -180...(-90):
result = "3 \(degree)"
default:
result = "not defined: \(degree)"
}
print(result)
}