【问题标题】:getting push notifications to appear in devices status bar让推送通知出现在设备状态栏中
【发布时间】:2015-09-16 12:56:48
【问题描述】:

我目前有一个 phonegap 应用程序,我在其中使用 pushPlugin 和警报框来显示传入的推送通知。但是,我希望这些消息出现在设备状态栏中。我需要做些什么才能让它们出现在那里吗?也许一些额外的配置?谢谢。

这是使用警告框的那段代码:

 case 'message':
      // if this flag is set, this notification happened while we were in the foreground.
      // you might want to play a sound to get the user's attention, throw up a dialog, etc.
      if (event.foreground) {
            console.log('INLINE NOTIFICATION');
            //var my_media = new Media("/android_asset/www/" + event.soundname);
            //my_media.play();
      } else {
        if (event.coldstart) {
            console.log('COLDSTART NOTIFICATION');
        } else {
            console.log('BACKGROUND NOTIFICATION');
        }
      }

      navigator.notification.alert(event.payload.message);//alert notification
      console.log('MESSAGE -> MSG: ' + event.payload.message);
      //Only works for GCM
      console.log('MESSAGE -> MSGCNT: ' + event.payload.msgcnt);
      //Only works on Amazon Fire OS
      console.log('MESSAGE -> TIME: ' + event.payload.timeStamp);
      break;

【问题讨论】:

    标签: android cordova push-notification phonegap-plugins


    【解决方案1】:

    我认为您正在寻找的是本地通知,您可以使用本地通知插件轻松实现。 https://github.com/Wizcorp/phonegap-plugin-localNotifications 的 WizCorp 插件是一个不错的插件,因此请将其添加到您的项目中:

    cordova plugin add https://github.com/Wizcorp/phonegap-plugin-localNotifications.git
    

    在你的代码中替换这个:

    navigator.notification.alert(event.payload.message);//alert notification
    

    用这个:

    localNotification.add(1, {message: event.payload.message}); //local notification
    

    将消息文本添加到设备的通知列表中,该列表显示在状态栏和通知托盘中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多