[英]Notification Action Intent not fired
Clicking on the notification action does not fire run the BroadcastReceiver 单击通知操作不会触发运行BroadcastReceiver
Intent cancelIntent = new Intent(c, NotificationBroadcast.class);
cancelIntent.setAction(CANCEL_UPLOAD);
cancelIntent.putExtra(EXTRA_REQUEST, new Request(request));
//c is ApplicationContext
PendingIntent cancel = getBroadcast(c,1, cancelIntent,
FLAG_CANCEL_CURRENT);
nb.addAction(R.drawable.close, c.getString(R.string.cancel), cancel);
NotificationBroadcast implementation NotificationBroadcast实现
public class AppNotification {
public static class NotificationBroadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Request cancel = cancelRequest((Request) intent.getParcelableExtra(EXTRA_REQUEST));
if (CANCEL_UPLOAD.equals(intent.getAction()))
cancel.clearFlag(FLAG_REQUEST);
updateRequest(context, cancel);
}
}
}
I expect NotificationBroadcast#onReceive to be called when the notification action is clicked but it is not being called; 我希望在点击通知操作时调用NotificationBroadcast#onReceive但是没有调用它;
NotificationBroadcast is not registered since I am using explicit intent
NotificationBroadcast未注册,因为我使用的是显式意图
That does not matter. 那不重要。 All receivers need to be registered, either via the manifest or via a
registerReceiver()
call on a Context
. 所有接收器都需要通过清单或通过
Context
上的registerReceiver()
调用进行registerReceiver()
。 In your case, since you are using a PendingIntent
for a notification action, you need to use the manifest option. 在您的情况下,由于您使用
PendingIntent
进行通知操作,因此您需要使用清单选项。
Your <receiver>
in the manifest does not need to have an <intent-filter>
, since you are using a explicit broadcast. 清单中的
<receiver>
不需要<intent-filter>
,因为您使用的是显式广播。 However, the <receiver>
element must still be there. 但是,
<receiver>
元素仍然必须存在。
Also, since you elected to have your receiver be a static
class, your android:name
for your <receiver>
needs to take that into account. 此外,由于您选择将接收器设置为
static
类,因此<receiver>
android:name
需要将其考虑在内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.