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

相关推荐
andyweike3 小时前
Android Automotive
android
又见情义3 小时前
记一次 RK3568 Android 13 蓝牙反复重启问题的排查与修复
android
hai_android3 小时前
Kotlin Flow combine 源码剖析:一个 Channel 如何优雅合并多条流
android·java·kotlin
敲代码的瓦龙5 小时前
Jetpack?ViewModel!!!
android·开发语言·kotlin·android-studio
Godikov5 小时前
Android 工控终端实战:从秒级卡顿到毫秒响应,SQLite/LitePal 性能优化全记录
android
星间都市山脉7 小时前
Android16 SystemService.onBootPhase 调用时机
android·java·linux·windows·ubuntu
swithun7 小时前
不用 WebView,我用 Kotlin + Compose Multiplatform 重写 Mermaid,并做了 2048 组对拍
android·开源·kotlin
AI吃大瓜8 小时前
人脸检测和行人检测4:Android实现YOLOv8 YOLO11 YOLO26人脸检测和人体检测(含源码,可实时检测)
android·yolo·人脸检测·人体检测·行人检测·yolo26
与海boy8 小时前
Prompt模版
android·prompt
FlightYe8 小时前
音视频修炼之编码器(一):AVC、HEVC编码器内部
android·linux·c++·音视频