Làm cách nào để đóng thanh trạng thái sau khi nhấp vào nút thông báo?Đóng thanh trạng thái khi thông báo nút được nhấp
tôi đã cố gắng this, nhưng tôi có một ngoại lệ:
java.lang.NoSuchMethodException: collapse []
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getMethod(Class.java:915)
...
Mã của tôi:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.icon)
.setContentTitle("Sync Failed")
.setContentText("Lorem ipsum dolor sit amet")
.setStyle(new NotificationCompat.BigTextStyle().bigText("Lorem ipsum dolor sit amet"))
.addAction(R.drawable.change, "Change Pass", pChangePass)
.addAction(R.drawable.remove, "Ignore", pIgnore)
.setAutoCancel(false);
mNotificationManager.notify(accountUnique, builder.build());
Tại lớp NotificationIntent
@Override
public void onReceive(Context context, Intent intent) {
int notificationID = intent.getExtras().getInt("NOT_ID");
this.callbackContext = StatusBarNotification.getCallback();
this.mNotificationManager = StatusBarNotification.getNotificationManager();
this.mNotificationManager.cancel(notificationID);
this.callbackContext.success(returnJSON(intent));
}
Bạn thực sự nên chấp nhận bình luận Sam Lu - giải pháp của bạn có thể ngừng làm việc trên bất kỳ phiên bản tiếp theo, bởi vì nó sử dụng không api công khai. Như bạn thấy bạn alredy đã phải thêm 'if api <= 16' - có thể bạn sẽ sớm cần thêm' if api <= 19' – imbryk
Đồng ý với nhận xét ở trên. Câu trả lời của Sam đơn giản hơn nhiều và không xử lý các số phiên bản. – Saik