Android notification for audio only

I have a countdown timer in my activity, and when it reaches zero, I send a notification to the status bar, which also plays the user wav file to alert the user. I only want the notification in the status bar to be displayed if the user is not using the application at that time, but I still want the wav file to play whether the timer application is visible or not.

Is it possible for an Android notification to sound an alert? I tried using MediaPlayer to play the wav file, but it uses its own volume settings, not the usual notification volume, so if your media has a low sound volume and the notification sound plays at a low level that I don't want. I want the sound to play in the same volume as other notifications.

I use this: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

And giving the sound as follows:

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd); 
+7
source share
4 answers

In the β€œAdd Sound” section of http://developer.android.com/guide/topics/ui/notifiers/notifications.html there is this note:

Note. If the default field includes DEFAULT_SOUND, the default sound cancels any sound specified by the sound field.

So, if you want to adjust only the sound, you can use -

 notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd); notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE; 
+5
source

According to my experiment, you can really send a notification without its appearing in the notification area, but still play sound.

All you have to do is build a notification builder and set a sound for it, but skip pending intentions, an icon, a content title and content text.

 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSound(your_sound_uri); notificationManager.notify(1234, builder.build()); 
+3
source
 Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Notification mNotification = new Notification.Builder(this) .setContentTitle("New Post!") .setContentText("Here an awesome update for you!") .setSmallIcon(R.drawable.ic_lancher) .setContentIntent(pIntent) .setSound(soundUri) .build(); 
0
source
 NotificationCompat.Builder builder= new NotificationCompat.Builder(this); 

three ways to setSound

 builder.setDefaults(Notification.DEFAULT_SOUND); builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); 
0
source

All Articles