我在android上工作,我已经使用gcm在我的应用中实现了推送通知功能。
我的目的是播放来自app assets或device sdcard的铃声,当只有与我的应用程序相关的推送通知到达安装的设备时。
最佳答案
1.在你的app/res下创建一个名为raw的文件夹/
2.在这个文件夹中复制并粘贴你的铃声
3.当您的应用程序通知通知通知时,请编写以下代码。!
SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
int iTmp = sp.load(context, R.raw.windows_8_notify, 1); // in 2nd param u have to pass your desire ringtone
sp.play(iTmp, 1, 1, 0, 0, 1);
MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.windows_8_notify); // in 2nd param u have to pass your desire ringtone
//mPlayer.prepare();
mPlayer.start();