fix:修复无法正确读取通知的错误,注册 NotificationBridge 插件并清空本地通知队列

This commit is contained in:
2025-11-28 10:07:18 +08:00
parent 550529af2e
commit cc2c376e9d
2 changed files with 13 additions and 34 deletions

View File

@@ -1,6 +1,16 @@
package com.echo.app;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.echo.app.notification.NotificationBridgePlugin;
// 主 Activity这里显式注册自定义的 NotificationBridge 插件,打通原生通知监听到前端的桥接
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// 注意:必须在 super.onCreate 之前向 bridgeBuilder 注册插件,
// 否则 Bridge 已经创建完成JS 侧会报 "plugin is not implemented on android"
registerPlugin(NotificationBridgePlugin.class);
super.onCreate(savedInstanceState);
}
}

View File

@@ -12,41 +12,10 @@ const nativeBridgeReady = isNativeNotificationBridgeAvailable()
/**
* 本地模拟通知缓存:
* - 浏览器环境:用于 Demo & Mock
* - 原生环境:作为 NotificationBridge 数据的补充兜底
* - 浏览器环境:用于 Demo & Mock,可通过 pushLocalNotification 主动注入
* - 原生环境:一般保持为空,仅在必要时作为 NotificationBridge 数据的补充兜底
*/
let localNotificationQueue = [
{
id: uuidv4(),
channel: '支付宝',
text: '支付宝提醒:你向 瑞幸咖啡 支付 ¥18.00',
createdAt: new Date().toISOString(),
},
{
id: uuidv4(),
channel: '微信支付',
text: '微信支付:美团外卖 实付 ¥46.50 · 订单已送达',
createdAt: new Date(Date.now() - 1000 * 60 * 8).toISOString(),
},
{
id: uuidv4(),
channel: '招商银行',
text: '招商银行:工资收入 ¥12500.00 已到账',
createdAt: new Date(Date.now() - 1000 * 60 * 32).toISOString(),
},
{
id: uuidv4(),
channel: '北京一卡通',
text: '北京一卡通:乘车扣款 3.00 元,扣款金额 3.00 元',
createdAt: new Date(Date.now() - 1000 * 60 * 45).toISOString(),
},
{
id: uuidv4(),
channel: '建设银行',
text: '建设银行信用卡:刷卡消费 人民币 86.20 元,消费商户 星巴克咖啡',
createdAt: new Date(Date.now() - 1000 * 60 * 60).toISOString(),
},
]
let localNotificationQueue = []
export const setRemoteNotificationFetcher = (fetcher) => {
remoteNotificationFetcher = typeof fetcher === 'function' ? fetcher : remoteNotificationFetcher