React-Native-FCM Android通知无法正常工作。

4

我第一次使用react-native-fcm,根据文档完成了所有的链结工作,并在Firebase控制台中使用云消息选项卡发送通知。

发送通知后,状态显示为已完成,在iOS上可以正常工作(收到通知),但在Android上没有反应。 我正在使用安装有Android N的小米设备进行测试。 这是我的build.gradle设置。

    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        applicationId "XXXXXX"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 39
        versionName "1.91"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

我找了很久都没能找到解决办法,请帮帮我!

2018年8月6日尝试后编辑

我试了很多方法都不行,然后我创建了一个新的firebase和react native项目。在这个项目中一切正常(可以收到通知)。之后我开始检查我的旧项目文件和新文件,经过多次实验,我发现问题出在 tools:node="replace" 上,因为使用了react-native-facebook-login时需要(在谷歌上找到的一些解决方案提示错误)。

现在请帮我看看这段Android代码应该如何修改,因为我猜想 tools:node="replace" 覆盖了我的fcm代码,使用了Facebook登录。根据这个参考文献,我不能去掉 tools:node="replace",否则app就会崩溃。

<application
      tools:node="replace" <-- this is culprit
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <receiver android:name="com.evollu.react.fcm.FIRLocalMessagingPublisher"/>
      <receiver android:enabled="true" android:exported="true"  android:name="com.evollu.react.fcm.FIRSystemBootEventReceiver">
        <intent-filter>
          <action android:name="android.intent.action.BOOT_COMPLETED"/>
          <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
          <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
      </receiver>
      <!-- <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/icon"/> -->
      <service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
      </service>
      <service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false">
        <intent-filter>
          <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
      </service>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:screenOrientation="portrait" android:name="com.facebook.react.devsupport.DevSettingsActivity" />

      <!--add FacebookActivity-->
      <activity
        tools:replace="android:theme"
        android:screenOrientation="portrait"
        android:name="com.facebook.FacebookActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

      <!--add CustomTabActivity-->
      <activity
        android:screenOrientation="portrait"
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
      </activity>

      <!--reference your fb_app_id-->
      <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/fb_app_id"/>
      <meta-data android:name="com.bugsnag.android.API_KEY"
        android:value="xxxxxxxxxxxxxx"/>
    </application>

你尝试过编辑 AndroidManifest.xml 文件吗? - MohamadKh75
@M.Khajavi 是的,我根据文档进行了操作。除此之外,我们需要添加什么吗? - Shubhanu Sharma
1个回答

1
即使您应该发布所有关于 android/build.gradle 和 android/app/build.gradle 的内容,我想告诉您,您应该使用 react-native-firebase,因为 react-native-fcm 不再接收新功能。
react-native-firebase引入了新的firebase消息传递和本地/远程通知功能。 它与其他firebase功能良好集成。 我建议新手们检查一下。
请注意,还有一些高级功能正在进行中:
- 当应用程序未运行时处理iOS远程通知 - 自定义iOS通知操作 - 对于现有的react-native-fcm用户,react-native-firebase现在可以完成react-native-fcm所能做的工作,因此在并行构建相同的东西是浪费精力。
由于我最近变得更加忙碌,并开始感到难以每天维护此存储库,而react-native-firebase有一个更大的团队/公司支持它,因此现有用户可以考虑迁移到react-native-firebase。
我创建了一个使用react-native-firebase作为迁移参考的示例项目。
react-native-fcm仍将接受PR和错误修复,但可能不再进行新的功能开发。

1
是的,我知道那个,今天我试图将其集成到我的项目中,但仍然没有效果。然后我克隆了React-Native-Firebase的启动包,并将其与我的Firebase链接起来(创建了一个新的Android应用程序并在android>app文件夹中添加了JSON),但对我来说也无济于事,我不知道自己缺失了什么。请查看此链接:https://stackoverflow.com/questions/50742795/push-notification-is-not-popping-up-react-native-firebase-with-starter-kit - Shubhanu Sharma
react-native-firebase的问题在于它的依赖项与其他库(如react-native-map)不兼容。 - Mr.Ghamkhar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接