Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

android - Disable sound from NotificationChannel

Today I started targeting API 26 which forced me to use Notification Channels.

My problem is that now on each new notification (including updates to it) an annoying sound is played.

How can I disable this sound?

I tried replacing this sound with a custom mp3 sound in order to then pass it a mp3 with silence in it, but this is ignored.

I'm just adding a notification which is of very low priority, basically giving the user the option to perform some actions after he has interacted with the app. There's no reason to be loud, the user will know that he can refer to the notification because he has done a certain thing with the app which he knows that will cause a notification to appear.

The user will really start getting annoyed by that sound.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want to keep the importance of your channel and just remove the sound notificationChannel.setSound(null, null); seems to do the job.

EDIT: Make sure to rename the channel (and delete the old one) to have it applied to existing users. (Channels can be created, but never modified by the app, only the user can.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...