Android O does not display service notification
As per the documentation, I made a change to the application to start services in the background with context.startForegroundService(Intent)
and then calls startForeground
on the service as before.
NotificationCompat.Builder notification = new
NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.icon)
.setContentText("Content")
.setOngoing(true)
.setContentInfo("Info")
.setContentTitle("Title");
startForeground(1, notification.build());
This correctly displays a notification on an Android N device, but on an Android O device it does not display a notification that only displays the new "running in the background ... click for more battery and data usage"
Isn't there something you need to properly display notifications on Android O?
+3
source to share
2 answers
The answer above doesn't work for me. You have to create a channel to work and then pass the channel ID.
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = "some_channel_id";
CharSequence channelName = "Some Channel";
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
notificationManager.createNotificationChannel(notificationChannel);
Then create a notification with the same cannelId
new NotificationCompat.Builder(this, channelId)
+1
source to share