NotificationBroadcastReceiverAndroidO extension NotificationBroadcastReceiver, поэтому мы реализуем код только в NotificationBroadcastReceiver, нам не нужно реализовывать код в NotificationBroadcastReceiverAndroidO

я есть уведомление о загрузке в моем приложении. Я добавил кнопку «Отмена» вNotificationCompat.Builder позвонив по телефонуaddAction() метод. Но кнопка не работает на устройстве Android O. Когда я нажимаю кнопку «Отмена», ничего не происходит. Но кнопка работает на Android <O.


мойNotification:

NotificationCompat.Builder notification = new NotificationCompat.Builder(context, channelId)
            .setContentTitle(title)
            .setSmallIcon(R.drawable.network_download)
            .setContentText(contentText)
            .setOngoing(true)
            .setContentIntent(null)
            .addExtras(idBundle)
            .addAction(R.drawable.cancel, context.getString(R.string.cancel), getCancelPendingIntent(context, id))
            .setProgress(100, 30, true);

мойPendingIntent :

private PendingIntent getCancelPendingIntent(Context context, int id){
    return PendingIntent.getBroadcast(
            context, id, new Intent("CANCEL_DOWNLOAD").putExtra("id", id), PendingIntent.FLAG_UPDATE_CURRENT);
}

Также у меня естьNotificationReceiver :

public static class NotificationReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if ("CANCEL_DOWNLOAD".equals(action) && context != null){
            int id = intent.getIntExtra("id", -1);
            NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            if (mgr != null)
                mgr.cancel(id);
            FtpManager.getInstance(new AppExecutors(), CredentialsManager.getInstance().getCredentials(context))
                    .cancelDownloading();
        }
    }
}

ВManifest файл у меня есть:

<receiver
        android:name="eu.warble.pjapp.util.NotificationsManager$NotificationReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="CANCEL_DOWNLOAD" />
        </intent-filter>
</receiver>

Ответы на вопрос(2)

Ваш ответ на вопрос