在服务中使用@Receiver AndroidAnnotation的方法(扩展FirebaseMessagingService)未调用

时间:2016-11-16 10:29:54

标签: android service broadcastreceiver android-annotations

我的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方法。我错过了什么!

0 个答案:

没有答案