React Native视频会议App前台服务类型不匹配崩溃求助
解决React Native视频会议应用前台服务类型不匹配导致的崩溃问题
问题根源
报错信息foregroundServiceType 0x000000C0 is not a subset of foregroundServiceType attribute 0x00000800 in service element of manifest的核心原因是:你把android:foregroundServiceType错误配置在了application标签,而不是对应前台服务的service标签。Android要求每个前台服务必须在自身的service声明中明确指定允许的类型,application标签的配置无法覆盖具体服务的类型要求。
0x000000C0是camera+microphone类型的组合值,而0x00000800对应location类型,说明你的前台服务实际使用的类型和代码中请求的完全不匹配,导致系统拒绝并崩溃。
修复步骤
1. 修正AndroidManifest.xml配置
移除application标签中的android:foregroundServiceType属性,找到@notifee对应的前台服务(通常是io.invertase.notifee.ForegroundService),给它添加正确的类型声明:
<manifest ...> <!-- 确保已添加所需权限 --> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" /> <application ...> <!-- 移除application标签内的android:foregroundServiceType --> <!-- 配置Notifee前台服务的类型 --> <service android:name="io.invertase.notifee.ForegroundService" android:foregroundServiceType="camera|microphone" android:stopWithTask="false" /> </application> </manifest>
2. 对齐代码中的前台服务类型
确保@notifee注册前台服务时,foregroundServiceTypes数组中的类型和Manifest里的完全一致:
import notifee from '@notifee/react-native'; import { AndroidImportance } from '@notifee/react-native'; async function startVideoCallForegroundService() { // 先请求通知权限 await notifee.requestPermission(); // 创建高优先级通知渠道(后台通话需要高优先级) const channelId = await notifee.createChannel({ id: 'video-call-channel', name: 'Active Video Call', importance: AndroidImportance.HIGH, }); // 启动前台服务 await notifee.displayNotification({ title: '视频通话中', body: '应用在后台保持通话连接', android: { channelId, foregroundService: { serviceId: 1001, // 自定义唯一ID foregroundServiceTypes: ['camera', 'microphone'], // 和Manifest类型严格对应 }, }, }); }
3. 额外检查项
- 确保项目的
targetSdkVersion>= 31(Android 12及以上),该版本开始强制要求前台服务声明具体类型。 - 修改Manifest后,彻底杀死应用再重新启动,避免缓存导致配置不生效。
- 确认没有其他第三方服务在同时使用前台服务,避免类型冲突。
验证效果
启动视频通话后切换到后台/最小化应用,检查通知栏是否显示前台服务通知,同时测试对方能否正常接收你的音视频。
内容的提问来源于stack exchange,提问作者Austin Ezeh
相关产品推荐
相关产品推荐

