Foreground Service with a Silent Notification

Doğukan Özdemir :

Context:

I have been using Google's LocationUpdatesForegroundService example project to learn a bit more about services.

I have downloaded the project via Github desktop and ran it on my phone, everything is great and the project does what it's intended to do.

My phone is Android 8.0.0, API 26

Problem:

The foreground service notification shows up on the status bar once the app is terminated, as soon as that happens I hear a notification sound(default sound). However, I would like the notification to be silent, like in some location-based apps(eg: Life360)

What I've tried so far:

None of the above have worked for me, I would really appreciate if someone could shed some light on this situation.

hfarhanahmed :

The solution is to use NotificationManager.IMPORTANCE_LOW and create a new channel for it. Once a channel is created, you can't change the importance (well, you can, but the new importance is ignored). The channel information appears to get stored permanently by the system and any channel created is only deleted when you uninstall the app. you can delete the channel as

nm.deleteNotificationChannel(nChannel.getId());

and recreate it with

nm.createNotificationChannel(nChannel);

via stack overflow answer here Disable sound from NotificationChannel

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=80467&siteId=1