如何在通知按鈕點擊後關閉狀態欄?單擊按鈕通知時關閉狀態欄
我試過this,但我有一個例外:
java.lang.NoSuchMethodException: collapse []
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getMethod(Class.java:915)
...
我的代碼:
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());
在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));
}
你真的應該接受薩姆·魯的評論 - 您的解決方案可能會停止在任何未來版本的工作,因爲使用了非公共API。正如你所看到的,你必須添加'如果api <= 16' - 可能很快你就需要添加'if api <= 19' – imbryk
同意上面的評論。 Sam的答案簡單得多,並且不涉及版本號。 – Saik