我想在后台或在应用程序中处于活动状态时在应用程序中显示通知
我可以获取令牌并在控制台Firebase中手动发送它,并且可以正常运行,因为我看到状态已完成,但是应用程序出现了此问题
我正在使用
react-native-fcm,
react-native-firebase
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.khadamaty">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_notif"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="my_default_channel"/>
<service
android:name=".java.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_ic_notification" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBb825RsIEAkFwJKk4PEb12cTXASe9sX70"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
- 错误日志
Android resource linking failed
Output: D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:21: error: resource mipmap/ic_notif (aka com.khadamaty:mipmap/ic_notif) not found.
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:78: error: resource color/colorAccent (aka com.khadamaty:color/colorAccent) not found.
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:81: error: resource drawable/ic_stat_ic_notification (aka com.khadamaty:drawable/ic_stat_ic_notification) not found.
error: failed processing manifest.
Command: C:\Users\jit\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\eaad08a303d2763f912063e432550147\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
C:\Users\jit\AppData\Local\Android\Sdk\platforms\android-28\android.jar\
--manifest\
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
-o\
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
-R\
@D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
--auto-add-overlay\
--java\
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
--custom-package\
com.khadamaty\
-0\
apk\
--output-text-symbols\
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\symbols\debug\R.txt\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
Output: D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:21: AAPT: error: resource mipmap/ic_notif (aka com.khadamaty:mipmap/ic_notif) not found.
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:78: AAPT: error: resource color/colorAccent (aka com.khadamaty:color/colorAccent) not found.
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:81: AAPT: error: resource drawable/ic_stat_ic_notification (aka com.khadamaty:drawable/ic_stat_ic_notification) not found.
error: failed processing manifest.
Command: C:\Users\jit\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\eaad08a303d2763f912063e432550147\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
C:\Users\jit\AppData\Local\Android\Sdk\platforms\android-28\android.jar\
--manifest\
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
-o\
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
-R\
@D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
--auto-add-overlay\
--java\
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
--custom-package\
com.khadamaty\
-0\
apk\
--output-text-symbols\
D:\Last Year\Second\Graduation project\khadamati_app\android\app\build\intermediates\symbols\debug\R.txt\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
答案 0 :(得分:0)
错误消息表明您缺少图像和颜色。最好添加这些。
转到/android/app/src/main/res/mipmap-*
文件夹并创建ic_launcher.png
的副本,并将其命名为ic_notif.png
。另外,在/android/app/src/main/res/drawable-*
文件夹中创建一个副本(如果不存在,则创建它们(drawable-mdpi,drawable-hdpi等),并命名图标ic_stat_ic_notification.png
的副本。
创建文件/android/app/src/main/res/values/colors.xml
并将其添加为内容:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorAccent">#FF0000</color>
</resources>
这应该会使错误消失。您可能错过了安装push模块代码的一些步骤。