Reputation: 2002
I am trying to use simple notification sound as the sound in my app. But I just can't get it to work. There's no sound at all when I use RingManager.TYPE_NOTIFICATION. I should mention that when I use TYPE_ALARM or TYPE_RINGTONE (or TYPE_ALL = it is TYPE_RINGTONE in my mobile phone) it works. I tried also with setVolume(), but no results.
When I send message to myself at this moment (from another phone) I can hear the notification sound.
Some people tried to help me but it is still not solved. Maybe somebody can give me the simplest project for eclipse that I can check if it works? Maybe it's just something wrong with my mobile phone? I have Samsung Galaxy S2.
Here's my code. What do I do wrong? Or what else should I check?
Uri _sound = RingtoneManager.getDefaultUri( RingtoneManager.TYPE_NOTIFICATION );
// _sound.toString() returns "content://settings/system/notification_sound"
// this doesn't work either
// Uri _sound = RingtoneManager.getActualDefaultRingtoneUri( getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION );
// _sound.toString() returns "content://media/internal/audio/media/10" if it can help
mp = new MediaPlayer();
try {
// doesn't change anything while using TYPE_NOTIFICATION
// mp.setVolume(1.0f, 1.0f);
// tried also mp.setDataSource(context, Settings.System.DEFAULT_NOTIFICATION_URI);
// but no effect
mp.setDataSource( getApplicationContext(), _sound );
mp.setLooping( false );
mp.prepare();
} catch( IOException e ) {}
mp.start();
Thanks.
Upvotes: 1
Views: 971
Reputation: 13172
You can try to use this syntax instead:
Uri _sound = RingtoneManager.getActualDefaultRingtoneUri(Context, RingtoneManager.TYPE_NOTIFICATION);
This works for me.
You can try this too:
mp.setDataSource(context, Settings.System.DEFAULT_NOTIFICATION_URI);
Upvotes: 2