Android Marshmallow 中的通知问题

Android notification issue in Marshmallow

我在我的应用程序中使用一个操作按钮创建了通知,它在 6.0 以下的设备上工作正常,但在 6.0 以上的设备上操作按钮没有被点击,而是整个通知被点击并且内容意图被触发而不是操作按钮未决意图,有谁知道如何在 Marshamallow 及更高版本中使用操作按钮。

下面是我的代码:-

Intent downloadCancel = new Intent();
    downloadCancel.setAction("CANCEL");
    PendingIntent cancelPI = PendingIntent.getBroadcast(this,1,downloadCancel, 0);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    {
        Notification.Action actionButton = new Notification.Action.Builder(android.R.drawable.ic_menu_close_clear_cancel,"Cancel",cancelPI).build();
        notification = new Notification.Builder(this)
                .setContentTitle(title)
                .setContentText(text)
                .setSmallIcon(R.drawable.ic_file_download_white_24dp)
                .setContentIntent(pendingIntent)
                .setTicker(text)
                .setWhen(0)
                .setPriority(Notification.PRIORITY_MAX)
                .addAction(actionButton).getNotification();
    }
    else
    {
        notification = new Notification.Builder(this)
                .setContentTitle(title)
                .setContentText(text)
                .setSmallIcon(R.drawable.ic_file_download_white_24dp)
                .setContentIntent(pendingIntent)
                .setTicker(text)
                .setWhen(0)
                .setPriority(Notification.PRIORITY_MAX)
                .addAction(android.R.drawable.ic_menu_close_clear_cancel, "Cancel", cancelPI).getNotification();
    }

使用

 NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_menu_close_clear_cancel, "Cancel", cancelPI).build();

而不是

Notification.Action actionButton = new Notification.Action.Builder(android.R.drawable.ic_menu_close_clear_cancel,"Cancel",cancelPI).build();

我不得不使用 remoteViews 来解决这个问题,没有其他选择