在我的应用程序中,我使用了 GCM 服务。我想在 onMessage 函数中发出哔哔声或播放一个小的 mp3 文件。
我的 GCMIntentService 是从 GCMBaseIntentService 扩展而来的。
有人可以分享代码或建议我如何实现这一目标。
谢谢
最佳答案
你可以使用:
Notification notification = new Notification(icon, title, when);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND; // To play default notification sound
notification.sound = Uri.parse("PATH_TO_YOUR_SOUND_FILE"); // to play custom notification sound
NotificationManager nm = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(System.currentTimeMillis(), notification);
关于android - GCMIntentService onMessage 触发时如何播放声音文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12664845/