cordova - Android本地后台通知没有标题

标签 cordova cordova-plugins localnotification

使用this plugin在 Ionic 项目中,当 GCM 推送到达时,我已经能够获取本地通知(使用 ngCordova 和适当的插件)。

代码流程有点像这样:

在抽象应用程序 Controller 的范围内,pushNotification 是通过引用全局 onNotification 函数(在角度范围之外)的 ecb 设置的,并添加了 localNotification。

在角度范围内声明一个 onclick 处理程序以引导用户进入正确的 View 。

问题是,当应用不在前台运行时,可能会出现以下不良行为:

  • 不显示通知标题(即使进行硬编码)
  • 未播放所需的声音(设备仅振动)
  • 当应用进入前台时,不会触发 onclick 通知。

我的通知代码如下所示:

window.plugin.notification.local.add({
  message:    e.payload.message,
  title:      e.payload.activity.name,
  sound:      'android.resource://' + package_name + '/raw/bounce',
  json:       JSON.stringify(e.payload),
  autoCancel: true,
});

有任何关于发生什么事的线索吗?

<小时/>

已修复:事实证明,当应用程序位于后台并且推送通知变成本地通知时,事件回调永远不会被调用 - 这是我忽略的功能。谢谢大家的时间和麻烦:/

最佳答案

试试这个,

public void notifyUser(){

    NotificationManager notificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(MyActivity.this, SomeActivity.class);

    //use the flag FLAG_UPDATE_CURRENT to override any notification already there
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification = new Notification(R.drawable.ic_launcher, "Some Text", System.currentTimeMillis());
    notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;

    notification.setLatestEventInfo(this, "This is a notification Title", "Notification Text", contentIntent);
    //10 is a random number I chose to act as the id for this notification
    notificationManager.notify(10, notification);   }

关于cordova - Android本地后台通知没有标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24410351/

相关文章:

javascript - 如何在使用 Angular 编写的 Web 和 PhoneGap 应用程序之间共享通用代码?

ios - phonegap 的 child 浏览器插件也打开 ios 嵌入式 webview 和 child 浏览器

cordova - 在 azure 移动服务(.net 后端)上使用 Ripple 身份验证失败

ios - 如何一天只重复一次 LocalNotification

IOS - 获取通知并决定做什么

android - ADB 命令行在安装过程中挂起 (PhoneGap)

android - ionic 2 中的 window.resolveLocalFilesystemUrl

android - 构建错误-Ionic Cordova 对 android 失败

cordova - 将插件安装到 Visual Studio Cordova 项目

flutter - Flutter 中的本地日程通知