Фоновое уведомление Flutter firebase Я нажал на уведомление об изображении, но оно показывает только текст, но если приложение открыто, оно работает нормально, но приложение завершено или минимизирует его отображение только по умолчанию Я пробовал все, но это не работает Я также упомянул об этом https://pub.dev/packages/firebase_messaging бесполезно.
проверить это изображение
фоновое уведомление не показывает это изображение?
Application.kt
package YOUR PACKAGE
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.view.FlutterMain
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this);
FlutterMain.startInitialization(this)
}
override fun registerWith(registry: PluginRegistry?) {
if (!registry!!.hasPlugin("io.flutter.plugins.firebasemessaging")) {
FirebaseMessagingPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
if (!registry!!.hasPlugin("com.dexterous.flutterlocalnotifications")) {
FlutterLocalNotificationsPlugin.registerWith(registry!!.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"));
}
}
}
MainActivity.kt
package YOUR PACKAGE
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
AndroidManifest. xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="YOUR PACKAGE"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name=".Application"
android:label="APP_NAME"
android:icon="@drawable/home_logo"
tools:replace="android:label">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Add below to ensure we get the payload when tapping on a notification -->
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
main.dart
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on message $message');
showNotification(message);
},
onBackgroundMessage: Platform.isIOS
? null
: myBackgroundMessageHandler,
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
showNotification(message);
},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
showNotification(message);
},
);
myBackgroundMessageHandler метод в том же main.dart
static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
final notification = message['notification'];
final data = message['data'];
print(notification);
}
Firebase отправляет уведомление json Rest API
#header:
Content-Type:application/json
Authorization:key=YOUR FIREBASE SERVER KEY
#body -> raw
{
"notification":{
"title":"Plan Expired",
"body":"Your plan has expired please upgrade your plan today"
},
"data": {
"image":"https://i.ytimg.com/vi/zZ72Ujn8Rfw/maxresdefault.jpg"
},
"to":"NOTIFICATION TOKEN"
}