当我的Notification
被触发时,我想播放MP3声音。为此,我在我的“res/raw”文件夹中放入了一个mp3文件,并使用以下指令:通知声音
notification.sound=Uri.parse("android.resource://"+getPackageName()+"/" + R.raw.mySound);
。
但是,当Notifications
出现时我没有声音!
有什么想法?
当我的Notification
被触发时,我想播放MP3声音。为此,我在我的“res/raw”文件夹中放入了一个mp3文件,并使用以下指令:通知声音
notification.sound=Uri.parse("android.resource://"+getPackageName()+"/" + R.raw.mySound);
。
但是,当Notifications
出现时我没有声音!
有什么想法?
简单地说这下面的时候通知时,将触发该块内部代码..
mMediaPlayer = new MediaPlayer();
mMediaPlayer = MediaPlayer.create(this, R.raw.mySound);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setLooping(true); // Set false if you don't want it to loop
mMediaPlayer.start();
我发现这里的例子 -
这是用来
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone ring = RingtoneManager.getRingtone(getApplicationContext(), notification);
ring.play();
} catch (Exception e) {}
另外的代码,如果你想自定义声音(因为我是你的),你应该使用这个代码取自here
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE
;
第二种方法是行不通的。它显示了我正在做的事情。 – Zelig63