簡體   English   中英

Worklight 6.1中的默認推送通知聲音

[英]Default push notification sound in Worklight 6.1

我正在使用Worklight推送通知,但在Android上,推送沒有聲音。 我想啟用默認聲音(如果可能,請啟用LED)。

我正在使用示例推送通知示例代碼。

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閃爍並播放電話的默認通知聲音“根據每個電話而有所不同”。

我希望這有助於回答您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM