【问题标题】:Push notification is only showing in the tray推送通知仅显示在托盘中
【发布时间】:2018-02-07 10:51:10
【问题描述】:

我正在使用 Azure Notification Hub 和 Phonegap 推送插件,并通过此有效负载向 Android 手机发送推送通知:

{  
   "data":{  
      "title":"Ex",
      "message":"Notification Hub test notification",
      "content-available":"1",
      "uuid":"6a1da769-e499-11e7-aa20-de2b503f5007",
      "category":"sales-offer"
   }
}

但问题是我只在托盘中收到带有图标的通知,它没有显示在带有信息的屏幕上。我需要打开托盘以获取信息。我希望它在屏幕上显示信息(正文、图标和标题)。

我可以在负载中添加一些东西,或者在我的应用中添加一个设置来改变这种行为吗?

【问题讨论】:

标签: android cordova azure notifications


【解决方案1】:

您需要配置默认通知渠道并增加重要性。

async function createNotificationChannel ({channelId, description, importance}) {
  if (device.platform.toLowerCase() !== 'android') {
    return false;
  }

  // code runs only on android platform :)
  const wAny: any = window;
  return new Promise((resolve, reject) => {
    wAny.PushNotification.createChannel(
      () => {
        resolve(true)
      },
      () => {
        resolve(false)
      },
      {
        id: channelId,
        description: description,
        importance: importance,
        visibility: 1,
        vibration: true
      }
    );
  });
}

在调用 PushNotification.init 之前,调用这个:

const channelCreated = await createNotificationChannel(
  {
    channelId: 'PushPluginChannel',
    description: 'Important notifications',
    importance: 5
  });

我还在旧设备的有效负载中添加了优先级:2。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    相关资源
    最近更新 更多