當應用程式處于后臺/應用程式關閉時如何保持我的AndroidNotificationDetails?
這里的代碼FirebaseMessaging.onMessage:
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
channelDescription: channel.description,
color: ControllerColors.getPrimaryColor(), // Color orange
icon: "@mipmap/ic_launcher"
)
)
);
});
這是我處理背景時的代碼:
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage remoteMessage) async
{
await Firebase.initializeApp();
await setupFlutterNotification();
FirebaseMessaging fcm = FirebaseMessaging.instance;
await fcm.getToken();
}
一切都很好,但是當應用程式在后臺時,app_name我在 AndroidNotificationDetails 中的顏色(橙色)不是橙色。
怎么解決?
uj5u.com熱心網友回復:
在應用程式的 android/app/src/main/AndroidManifest.xml 檔案中撰寫這些代碼:
<application
android:usesCleartextTraffic="true"
android:label="your app name"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorPrimary" />
.....
</application>
然后將通知圖示 .png(名稱 - notification_icon)放在 android/app/src/main/res/drawable 檔案夾中。然后將這段代碼寫在android/app/src/main/res/values/styles.xml檔案中:
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<color name="colorPrimary">#your_hex_color</color>
....
</resources>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/505213.html
標籤:Google Cloud Collective 扑 火力基地 镖 firebase-云消息传递
