gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:38:35 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com