这是假设在设置通知时发出声音的功能
private void playRingtone() {
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
try {
MediaPlayer mp = MediaPlayer.create(this, R.raw.notification_ringtone);
mp.start();
} catch (IllegalStateException e) {
Log.d(TAG, "MediaPlayer problem");
e.printStackTrace();
}
}
}
使用调试器一切顺利但没有播放声音。 WHY ???
答案 0 :(得分:0)
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource("android.resource://YOURPACKAGE_NAME/raw/"+file anme);
mediaPlayer.prepare();
mediaPlayer.start();
}catch(Exceptions e){
}