我的service
显示notification
取消并接受action
。我想在@Receiver
中使用service
(androidannotation libs)来处理取消操作。这是我的代码:
private PendingIntent setupCancelIntent(String id, int notificationId) {
//set up pending intent for cancel action
Intent dismissIntent = new Intent(CANCEL_ACTION);
dismissIntent.putExtra(Constant.ID, id);
dismissIntent.putExtra(Constant.NOTIFICATION_ID, notificationId);
return PendingIntent.getBroadcast(this, notificationId, dismissIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
@Receiver(actions = CANCEL_ACTION)
public void actionCancel(@Receiver.Extra(Constant.ID) String id,
@Receiver.Extra(Constant.NOTIFICATION_ID) int notificationId, Context context) {
Toast.makeText(context, "Cancel action " + id, Toast.LENGTH_SHORT).show();
if (notificationId != -1) {
NotificationManager manager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(notificationId);
}
}
我的通知已显示,但按取消按钮时,不会调用actionCancel方法。我错过了什么!