[ACCEPTED]-How do I access Android's default beep sound?-beep
... use the default android beep sound (like 11 when you adjust the ringer volume) ...
On 10 my Cyanogen 7 Nexus One and my old stock 9 T-Mobile Pulse Mini (the latter from memory), as 8 far as I can hear, this is is exactly the 7 default beep sound on volume change:
final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
You 6 seem to be asking for an alternative to 5 ToneGenerator
, but I think it gives you exactly what 4 you want in two lines.
Here are some other 3 likely ToneGenerator
sounds I tried that were not a match 2 (the first two might be useful as alternates 1 to the volume beep):
// Double beeps: tg.startTone(ToneGenerator.TONE_PROP_ACK);
// Double beeps: tg.startTone(ToneGenerator.TONE_PROP_BEEP2);
// Sounds all wrong: tg.startTone(ToneGenerator.TONE_CDMA_KEYPAD_VOLUME_KEY_LITE);
public void playSound(Context context) throws IllegalArgumentException,
SecurityException,
IllegalStateException,
IOException {
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
MediaPlayer mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(context, soundUri);
final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
// Uncomment the following line if you aim to play it repeatedly
// mMediaPlayer.setLooping(true);
mMediaPlayer.prepare();
mMediaPlayer.start();
}
}
I found another answer:
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
credit goes to https://stackoverflow.com/a/9622040/737925
0
You can access Android's default beeb sound 2 via ToneGenerator class.
import android.media.AudioManager;
import android.media.ToneGenerator;
ToneGenerator toneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, 200);
toneGenerator.startTone(ToneGenerator.TONE_CDMA_EMERGENCY_RINGBACK);
More info on how 1 they sound: https://developer.android.com/reference/android/media/ToneGenerator and https://www.youtube.com/watch?v=HVu7K9W1_BM
the easy way is to use instance of ToneGenerator 1 classe:
//declaration
ToneGenerator toneG;
//using any where`
if(val>=taux_max)
{
taux_text.setTextColor(warnning_col);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); //200 is duration in ms
}
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.