반응형
Android의 기본 경고음에 액세스하려면 어떻게해야합니까?
버튼이 눌 렸음을 알리는 신호음이 울리도록하고 싶습니다. 내 자신의 mp3 음악 파일을 가져 오거나 ToneGenerator를 사용하는 대신 기본 Android 경고음 (벨소리 볼륨을 조정할 때와 같은)을 사용하는 방법을 알고 싶습니다.
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();
}
}
다른 답을 찾았습니다.
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
크레딧은 https://stackoverflow.com/a/9622040/737925 로 이동합니다.
... 기본 Android 경고음 사용 (예 : 벨소리 볼륨을 조정할 때) ...
Cyanogen 7 Nexus One과 이전 재고 T-Mobile Pulse Mini (메모리의 후자)에서들을 수있는 한, 이것이 바로 볼륨 변경시 기본 경고음 소리입니다.
final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
에 대한 대안을 요청하는 것 같지만 ToneGenerator
두 줄로 원하는 것을 정확하게 제공한다고 생각합니다.
다음은 ToneGenerator
내가 시도했지만 일치하지 않았을 가능성이있는 몇 가지 소리입니다 (처음 두 개는 볼륨 경고음 대신 유용 할 수 있음).
// 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);
쉬운 방법은 ToneGenerator 클래스의 인스턴스를 사용하는 것입니다.
//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
}
참조 URL : https://stackoverflow.com/questions/6462105/how-do-i-access-androids-default-beep-sound
반응형
'Nice programing' 카테고리의 다른 글
메서드 숨기기와 재정의 (0) | 2021.01.09 |
---|---|
Ruby on Rails-정적 메서드 (0) | 2021.01.09 |
명령 줄을 통해 CSV를 mysql로 가져 오기 (0) | 2021.01.09 |
서버 구성에 의해 거부 된 클라이언트 (0) | 2021.01.09 |
문자열을 문자 배열로 Java (0) | 2021.01.09 |