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...

相关推荐
fundroid2 小时前
Android Studio + Gemini:重塑安卓 AI 开发新范式
android·android studio·ai编程
vortex53 小时前
谷歌黑客语法挖掘 SQL 注入漏洞
android·数据库·sql
-指短琴长-6 小时前
MySQL快速入门——基本查询(下)
android·mysql·adb
stevenzqzq7 小时前
android lambda回调
android
林北北的霸霸10 小时前
django初识与安装
android·mysql·adb
Java 码农11 小时前
MySQL EXPLAIN 详解与优化指南
android·mysql·adb
stevenzqzq15 小时前
Android Hilt 入门教程_传统写法和Hilt写法的比较
android
wuwu_q16 小时前
用通俗易懂方式,详细讲讲 Kotlin Flow 中的 map 操作符
android·开发语言·kotlin
_李小白16 小时前
【Android FrameWork】第五天:init加载RC文件
android
2501_9160074716 小时前
手机使用过的痕迹能查到吗?完整查询指南与步骤
android·ios·智能手机·小程序·uni-app·iphone·webview