在Android的推送通知自定义音效(GCM) [英] Custom sound in Android Push Notifications (GCM )

查看:1718
本文介绍了在Android的推送通知自定义音效(GCM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何能接受一个Android推送通知时播放的自定义声音?

How can I play a custom sound when receiving an Android Push Notification?

在我的应用程序可以通过使用媒体播放器进行控制。该APP之外,我找不到正确的路径的音频文件。我已经有/ android_assets /网络/尝试WWW /,但总是有默认的声音,当您收到应用程序之外的推送通知。

Within the app I can control this by using the media player. Outside the APP I can not find the correct path to the audio file . I already have "/android_assets/www/" tried "www/", but there is always the default sound when you receive a push notification outside the app.

推荐答案

首先,你需要添加原始文件夹中的新的声音文件res文件夹下。

First of all, you would need to add the new sound file in raw folder under the res folder.

既然是科尔多瓦应用程序,您使用的是科尔多瓦推Plugin.There一个名为com.plugin.gcm.In的包开包GCMIntentService.java.Under在

Since it is cordova Application,you are using Cordova push Plugin.There is a package called com.plugin.gcm.In that package open GCMIntentService.java.Under the

    public void createNotification(Context context, Bundle extras)

方法,应该在此方法结束

method ,there should be a line at the end of this method

    mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build());

刚刚与以下$ C $替换行CS

Just replace the line with the following codes

    Notification notification = mBuilder.build();
    notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "/your_sound_file_name.mp3");
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    mNotificationManager.notify((String) appName, NOTIFICATION_ID, notification);

这篇关于在Android的推送通知自定义音效(GCM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆