Elad Benda
Elad Benda

Reputation: 36656

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 ?

Upvotes: 0

Views: 1580

Answers (1)

Pararth
Pararth

Reputation: 8134

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(?)

Upvotes: 2

Related Questions