Android GCMinentService onMessage启动时如何播放声音文件?

Android GCMinentService onMessage启动时如何播放声音文件?,android,android-mediaplayer,google-cloud-messaging,Android,Android Mediaplayer,Google Cloud Messaging,在我的应用程序中,我使用的是GCM服务。我想在onMessage功能中发出嘟嘟声或播放一个小mp3文件 我的GCMIntentService是从GCMBaseintService扩展而来的 有人可以分享代码或建议我如何实现这一点 谢谢您可以使用: Notification notification = new Notification(icon, title, when); notification.flags |= Notification.FLAG_AUTO_CANCEL; notifica

在我的应用程序中,我使用的是GCM服务。我想在onMessage功能中发出嘟嘟声或播放一个小mp3文件

我的GCMIntentService是从GCMBaseintService扩展而来的

有人可以分享代码或建议我如何实现这一点

谢谢

您可以使用:

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);