Oreo - Foreground service does not show foreground notification

后端 未结 3 649
醉酒成梦
醉酒成梦 2021-01-31 17:37

So far, I\'ve adjsuted my code to use ContextCompat.startForegroundService(context, intentService); to start my service. This way, it works on android < 26 and o

3条回答
  •  感动是毒
    2021-01-31 18:06

      // Since android Oreo notification channel is needed.
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    NotificationChannel channel = new NotificationChannel(channelId,
                            getString(R.string.app_name),
                            NotificationManager.IMPORTANCE_HIGH);
    
                    AudioAttributes attributes = new AudioAttributes.Builder()
                            .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                            .build();
    
    
                    channel.setDescription(data.get("body"));
                    channel.enableLights(true);
                    channel.enableVibration(true);
                    channel.setSound(SoundUri, attributes); // This is IMPORTANT
    
                    notificationManager.createNotificationChannel(channel);
    
    
                }
    

提交回复
热议问题