Важность уведомления всегда средняя для обслуживания переднего плана - PullRequest
0 голосов
/ 25 сентября 2018

Я прочитал, что важность уведомлений для служб переднего плана должна быть по меньшей мере НИЗКОЙ, но когда я пытаюсь изменить значение на НИЗКАЯ или ВЫСОКАЯ, она игнорируется, а уведомление остается в СРЕДНЕМ значении.Почему и как это можно исправить?

Фрагмент кода:

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            String id = SYNC_CHANNEL;
            String name = getApplicationContext().getResources().getString(R.string.sync_data);
            String description = getApplicationContext().getResources().getString(R.string.sync_progress);
            int importance = NotificationManager.IMPORTANCE_LOW; // Setting importance

            NotificationChannel channel = new NotificationChannel(id, name, importance);
            channel.setDescription(description);
            channel.enableLights(false);
            channel.enableVibration(false);

            if (notificationManager == null) {
                return;
            }
            notificationManager.createNotificationChannel(channel);

            NotificationCompat.Builder b = new NotificationCompat.Builder(getApplicationContext(), id);
            b.setSmallIcon(R.drawable.ic_refresh)
                    .setContentTitle(getApplicationContext().getResources().getString(R.string.app_name))
                    .setContentText(getApplicationContext().getResources().getString(R.string.sync_data))
                    .setOngoing(true);

            startForeground(1547, b.build());

1 Ответ

0 голосов
/ 11 декабря 2018

Поскольку приоритетным является сервис, который должен заботить пользователя, он делает следующее:

 /**
 * Min notification importance: only shows in the shade, below the fold.  This should
 * not be used with {@link Service#startForeground(int, Notification) Service.startForeground}
 * since a foreground service is supposed to be something the user cares about so it does
 * not make semantic sense to mark its notification as minimum importance.  If you do this
 * as of Android version {@link android.os.Build.VERSION_CODES#O}, the system will show
 * a higher-priority notification about your app running in the background.
 */
public static final int IMPORTANCE_MIN = 1;
...