1
我正在使用Jelly Bean丰富的通知系统,并且在通知中添加了两项操作。我遇到的问题是行为似乎被禁用。丰富的通知操作无法点击
这个想法是为每个动作设置一个PendingIntent
,并在我注册的BroadcastReceiver中获得通知,以处理两个意图中的动作。
以下是创建通知代码:
Intent startIntent = new Intent(Notifications.START);
Intent resetIntent = new Intent(Notifications.RESET);
PendingIntent startPendingIntent = PendingIntent.getBroadcast(ctx,
whichOne, startIntent,
Intent.FLAG_RECEIVER_REPLACE_PENDING);
PendingIntent resetPendingIntent = PendingIntent.getBroadcast(ctx,
whichOne, resetIntent,
Intent.FLAG_RECEIVER_REPLACE_PENDING);
[...]
notificationBuilder = new Notification.Builder(ctx)
.setContentTitle(s)
.setContentText("")
.setContentIntent(appIntent)
.setSmallIcon(R.drawable.ic_launcher)
.addAction(R.drawable.play,
ctx.getString(R.string.START), startPendingIntent)
.addAction(R.drawable.reload,
ctx.getString(R.string.RESET_TIMER),
resetPendingIntent);
[...]
然后我注册Receiver
这样的:
IntentFilter filter = new IntentFilter();
filter.addAction(Notifications.START);
filter.addAction(Notifications.RESET);
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, intent.getAction(), Toast.LENGTH_LONG)
.show();
}
};
registerReceiver(receiver, filter);
我的问题是行动似乎被禁用。我无法点击它们,它们以典型的禁用alpha文本颜色显示。