对我来说,您的示例代码有效
所以请确保您已安装、授予权限并正确链接。
(a) 检查 android/build.gradle 是否有
buildscript {
...
dependencies {
...
classpath('com.google.gms:google-services:4.3.3')
...
}
}
(b) 签入 android/app/build.gradle
dependencies {
...
implementation 'com.google.firebase:firebase-analytics:17.3.0'
implementation project(':react-native-push-notification')
...
}
apply plugin: 'com.google.gms.google-services'
(c) 签入 MainApplication.java
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
(d) 签入 android/app/src/main/res/values/colors.xml(如果文件不存在则创建)。
<resources>
<color name="white">#FFF</color>
</resources>
(e) 签入 android/app/src/main/AndroidManifest.xml
.....
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application ....>
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="false"/>
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<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"/>
</intent-filter>
</receiver>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
.....