【问题标题】:More than one button with pending intent on notification with remoteView多个按钮,具有通过 remoteView 通知的待定​​意图
【发布时间】:2015-05-01 15:29:30
【问题描述】:

我有一个使用 remoteView 的通知。在通知上,我有 3 个按钮,每个按钮都有自己的pendingIntent。出于某种原因,只有我使用 setOnClickPendingIntent 添加的最后一个pendingIntent 有效。

这里有一些

    Intent intentPause = new Intent(context, BluetoothConnectionService.class);
    intentPause.putExtra("pause", device.device.getAddress());
    Intent intentIncrease = new Intent(context, BluetoothConnectionService.class);
    intentIncrease.putExtra("inc", device.device.getAddress());
    PendingIntent pendingIntentPause = PendingIntent.getService(context, 0, intentPause, PendingIntent.FLAG_CANCEL_CURRENT);
    PendingIntent pendingIntentIncrease = PendingIntent.getService(context, 0, intentIncrease, PendingIntent.FLAG_CANCEL_CURRENT);

    RemoteViews expandedView = new RemoteViews(context.getPackageName(), R.layout.notification_layout);

    expandedView.setOnClickPendingIntent(R.id.noti_pause_heat_button, pendingIntentPause);
    expandedView.setOnClickPendingIntent(R.id.noti_inc_heat_button, pendingIntentIncrease);



Notification notification = new Notification.Builder(context)
        .setContentTitle(this.device.getName())
                        .setSmallIcon(R.drawable.inu_small)
                        .setContentText("" + this.notificationId)
        .setContent(expandedView)
                    .build();

【问题讨论】:

    标签: android notifications android-pendingintent remoteview


    【解决方案1】:

    为每个PendingIndent 使用不同的requestCodegetService 的第二个参数)。例如

    PendingIntent pendingIntentPause = PendingIntent.getService(context, 0, intentPause, PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent pendingIntentIncrease = PendingIntent.getService(context, 1, intentIncrease, PendingIntent.FLAG_UPDATE_CURRENT);
    

    【讨论】:

    • 谢谢您的先生!我不知道为什么你的回答没有被接受
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多