gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:57:37 25 4
gpt4 key购买 nike

使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com