Capacitor 框架下解决One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be ...

背景

在适配我们星光 MES APP在手机端的时候,星光 APP启动报错:

vbnet 复制代码
Caused by: java.lang.SecurityException: com.sancaiwulian.starmes: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

问题分析

这个问题是在 Android 14 版本以上才会出现,网上有讨论 stackoverflow.com/questions/7...

出现这个问题是我们星光 APP需要监听到扫码抢的事件通知,所以,我们采用了 capacitor-intents 这个插件。看它的源码:

java 复制代码
this.getContext().registerReceiver(receiverMap.get(callBackID), ifilt);

可以看到,它在注册监听的时候没有添加 RECEIVER_EXPORTED (表示可以监听其他 APP 的事件通知) 或 RECEIVER_NOT_EXPORTED (表示只能监听自己 APP 的事件通知)参数。

解决方法

看已经有人在自己的 fork 的仓库里修复了这个问题:

github.com/prathap-red...

但他没有发布最新的包,所以,你自己也用不了。

看来只能自己 fork 一份,重新发一个版本就好。@nantajs/capacitor-intents

使用的时候替换下原先的包(将包capacitor-android-intents替换为**@nanta/capacitor-intents**),其他都不需要变。

bash 复制代码
npm install @nanta/capacitor-intents
npx cap sync

www.npmjs.com/package/@na...

改动源码: github.com/nantajs/cap...

相关推荐
安卓理事人14 分钟前
安卓图表MpAndroidChart使用
android
奋斗的小鹰1 小时前
在已有Android工程中添加Flutter模块
android·flutter
介一安全2 小时前
【Frida Android】实战篇13:企业常用非对称加密场景 Hook 教程
android·网络安全·逆向·安全性测试·frida
lin62534222 小时前
Android右滑解锁UI,带背景流动渐变动画效果
android·ui
鹏多多5 小时前
Flutter输入框TextField的属性与实战用法全面解析+示例
android·前端·flutter
2501_916008895 小时前
iOS 开发者工具全景图,构建从编码、调试到性能诊断的多层级工程化工具体系
android·ios·小程序·https·uni-app·iphone·webview
Winter_Sun灬6 小时前
CentOS 7 编译安卓 arm64-v8a 版 OpenSSL 动态库(.so)
android·linux·centos
柯南二号6 小时前
【大前端】【Android】用 Python 脚本模拟点击 Android APP —— 全面技术指南
android·前端·python
龚礼鹏6 小时前
图像显示框架六——SurfaceFlinger的初始化以及任务调度(基于Android 15源码分析)
android
壮哥_icon6 小时前
Android 使用 PackageInstaller 实现静默安装,并通过 BroadcastReceiver 自动重启应用
android·gitee·android-studio·android系统