3
在我的應用程序中,我正在使用GCM服務。我想在onMessage功能上發出嘟嘟聲或播放小型mp3文件。如何在GCMIntentService onMessage觸發時播放聲音文件?
我的GCMIntentService是從GCMBaseIntentService擴展而來的。
有人可以分享代碼或建議我如何實現這一點。
感謝
在我的應用程序中,我正在使用GCM服務。我想在onMessage功能上發出嘟嘟聲或播放小型mp3文件。如何在GCMIntentService onMessage觸發時播放聲音文件?
我的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);