我第一次使用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>