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文本顏色顯示。