android - GCMIntentService onMessage 触发时如何播放声音文件?

标签 android android-mediaplayer google-cloud-messaging

在我的应用程序中,我使用了 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/

相关文章:

java - Android 中的列表(特别是 RecyclerView 和 CardView)如何工作

java - 将android模拟器指向本地域

Android mediaplayer 单例服务不会停止播放

Android ExoPlayer : Does it solve gapless/seamless playback issue that is broken for the Android Media Player

android - 单击后退按钮时音乐播放器崩溃

android - 上传到 Google Play 商店时为应用程序启用 GCM

android - 在 Android 上找不到来源

java - 滚动时 ListView 中的开关状态不稳定

android - 有什么方法可以自定义消息 "This app won' t 运行,除非您更新 Google Play 服务”或根据用户选择跳过消息

android - GCM ACCOUNT_MISSING 错误