我有以下內容的意圖通知:通知 - 點擊火災錯誤的PendingIntent
clickIntent = PendingIntent.getService(
getApplicationContext(),
Constants.REQUEST_CODE_NOTIFICATION_OTHER,
new Intent(getApplicationContext(), MainService.class)
.putExtra(Constants.EVENT, Constants.EVENT_TOGGLE_BLACK),
PendingIntent.FLAG_UPDATE_CURRENT);
,並與下面的操作意圖一個動作:
PendingIntent closeIntent = PendingIntent.getService(
getApplicationContext(),
Constants.REQUEST_CODE_NOTIFICATION_OTHER,
new Intent(getApplicationContext(), MainService.class)
.putExtra(Constants.EVENT, Constants.EVENT_DISABLE_SERVICE),
PendingIntent.FLAG_UPDATE_CURRENT);
當我點擊該通知,收盤意圖被解僱。爲什麼?
這裏是我創建通知:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(text))
.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(details)))
.setSmallIcon(R.drawable.ic_not)
.setContentIntent(clickIntent)
.setOngoing(true);
boolean showCloseButton = MainApp.getPrefs().enableCloseServiceButtonInNotification();
if (showCloseButton)
builder.addAction(R.drawable.ic_close_black_24dp, getString(R.string.stop_service), closeIntent);
嘗試改變他們使用的代碼..都使用Constants.REQUEST_CODE_NOTIFICATION_OTHER – W0rmH0le
我只是有這個變量,因爲我讀過這應該不是0.我會盡力... – prom85