You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native OneSignal 3.9.3适配Android12后无法接收推送通知

修复React Native OneSignal 3.9.3在Android 12(targetSdk31)下无法接收推送的配置遗漏

以下是你当前配置中缺失或错误的部分,对应修复方案:

1. 修正GcmBroadcastReceiver的android:exported属性

Android 12要求接收系统级FCM/C2DM广播的组件必须设置android:exported="true",你当前将其设为false会导致系统无法触发该接收器,直接影响推送接收。修正后的配置:

<receiver
    android:exported="true"
    android:name="com.onesignal.GcmBroadcastReceiver"
    android:permission="com.google.android.c2dm.permission.SEND"
    tools:replace="android:exported">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="com.myapp" />
    </intent-filter>
</receiver>

2. 添加OneSignal FCM服务配置并设置正确的exported属性

OneSignal 3.x依赖GcmIntentService处理推送消息的后台逻辑,你当前的Manifest中缺少该服务的配置,且在Android 12下需要明确设置android:exported:

<service
    android:name="com.onesignal.GcmIntentService"
    android:exported="false"
    tools:replace="android:exported" />

<service
    android:name="com.onesignal.SyncService"
    android:exported="false"
    tools:replace="android:exported" />

3. 完善BootUpReceiver的Intent Filter

你的BootUpReceiver未配置触发动作,导致设备重启后无法重新注册推送,添加以下intent-filter:

<receiver
    android:name="com.onesignal.BootUpReceiver"
    android:exported="true"
    tools:replace="android:exported">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    </intent-filter>
</receiver>

4. 确认通知渠道配置(Android 8.0+要求)

虽然应用内通知正常,但推送通知需要正确的通知渠道。确保在Manifest的<application>标签内添加FCM默认渠道的meta-data:

<meta-data
    android:name="com.google.firebase.messaging.default_notification_channel_id"
    android:value="@string/default_notification_channel_id" />

同时在res/values/strings.xml中定义渠道ID:

<string name="default_notification_channel_id" translatable="false">onesignal_default_channel</string>

完成以上配置后,重新编译打包应用,测试推送接收功能。

内容的提问来源于stack exchange,提问作者gloriamaris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 08:00:54