简体   繁体   中英

how to disable sound on push notification?

I saw the documentation :

public Uri sound

Added in API level 1
The sound to play.

To play the default notification sound, see defaults.

but how do I disable sound playing? sending Uri == null ?

If you don't call setSound(uri) with NotificationBuilder, the sound won't play. Eg. The following would play the default sound for notification:

Uri alarmSound = RingtoneManager
                .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("title")
                .setSound(alarmSound); 

Just remove ".setSound(alarmSound)" and it won't play the sound, like:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("title");  

Hope i got the question right(?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM