首页 > 解决方案 > 通知重要性对于前台服务始终为中

问题描述

我已经读过前台服务的通知重要性至少应该是 LOW,但是当我尝试将重要性更改为 LOW 或 HIGH 时,它会被忽略并且通知仍然处于中等重要性。为什么以及如何解决这个问题?

代码片段:

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());

标签: androidserviceandroid-8.0-oreo

解决方案


推荐阅读