Worklight 6.1中的默认推送通知声音
我正在使用Worklight推送通知,但在Android上推送没有声音。我想启用默认声音(如果可能的话,LED)。Worklight 6.1中的默认推送通知声音
我正在使用示例推送通知示例代码。
var notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});
我也试着像分配或notification.GCM.sound = "true"
一个notification.GCM.sound = "default"
值,但它是打连续的声音在某些设备上。
要做到这一点,你将不得不修改您的应用程序。 Worklight将在Android项目中生成一个骨架类,GCMIntentService.java
为了添加声音并闪烁LED通知灯,您必须重写GCMIntentService类中的notify方法。您的文件将如下所示:
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
public class GCMIntentService extends
com.worklight.androidgap.push.GCMIntentService {
@Override
public void notify(Context context, String alert, int badge, String sound,
Intent intent) {
super.notify(context, alert, badge, sound, intent);
// call helper method
notifyLightAndSound(context);
}
@Override
public void notify(Context context, String tickerText) {
super.notify(context, tickerText);
// call helper method
notifyLightAndSound(context);
}
private void notifyLightAndSound(Context context) {
// Get the default notification sound
Uri notification = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// build a notification with the light and sound
// LED will be on for 1000 ms and off for 800 ms until you turn on your
// screen
Notification n = new Notification.Builder(context)
.setLights(Notification.DEFAULT_LIGHTS, 1000, 800)
.setSound(notification).build();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// play sound and flash LED
mNotificationManager.notify(4, n);
}
}
这会使LED闪烁并播放手机的默认通知声音,“根据每部手机的不同而不同”。
我希望这有助于回答你的问题。
LED通知不可用。
在这里看到:Led not working on Android using Unified Push Notification of worklight (6.0.0.2)-
要使用自定义通知声音(见supported media formats):
- 如果文件夹不存在,在
yourProject\apps\yourApp\android\native
添加现有native\res
文件夹下一个名为raw
文件夹 - 将声音文件放在
raw
文件夹中
- 如果文件夹不存在,在
-
要使用默认的通知声音,请尝试重新发送空:
notification.GCM.sound = "";
我试过了,但它保持通知无声。 – Eldeeb 2015-01-21 13:41:22
因此,另一种解决方案是下载默认声音文件并将其添加为自定义声音文件。 :) – 2015-01-21 13:46:48
你想添加自己的自定义声音吗? – 2015-01-21 02:24:17
我想使用默认通知声音,这是从移动到另一个不同。就像本机应用程序一样。 – Eldeeb 2015-01-21 14:29:54
检查我发布的答案,并让我知道它是否有帮助。 – 2015-01-22 19:54:53