私は Jelly Bean の豊富な通知システムを使用しており、通知に 2 つのアクションを追加しています。私が抱えている問題は、アクションが無効になっているように見えることです。
アイデアはPendingIntent
、アクションのそれぞれに a を設定し、2 つのインテントでアクションを処理するために登録した 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);
私が抱えている問題は、アクションが無効になっているように見えることです。クリックできず、通常の無効なアルファ テキストの色で表示されます。