Android 当应用程序处于后台时,颤振通知为空
当应用程序在后台时,不会调用onResume,但我会在托盘中收到某种默认通知,其中有一个空白图标,没有图像 当我单击此通知时,会调用onResume并打开应用程序,但不会导航到正确的路径 当Flatter应用程序位于前台时,Firebase消息的行为与预期一致。 -调用onMessage,通知在托盘中有图标和图像 我想知道通知/消息的设置是否在错误的位置Android 当应用程序处于后台时,颤振通知为空,android,flutter,android-notifications,flutter-dependencies,Android,Flutter,Android Notifications,Flutter Dependencies,当应用程序在后台时,不会调用onResume,但我会在托盘中收到某种默认通知,其中有一个空白图标,没有图像 当我单击此通知时,会调用onResume并打开应用程序,但不会导航到正确的路径 当Flatter应用程序位于前台时,Firebase消息的行为与预期一致。 -调用onMessage,通知在托盘中有图标和图像 我想知道通知/消息的设置是否在错误的位置 class NotificationIcon extends StatefulWidget { @override Notific
class NotificationIcon extends StatefulWidget {
@override
NotificationIconState createState() => NotificationIconState();
}
class NotificationIconState extends State<NotificationIcon> {
FirebaseMessaging firebaseMessaging = new FirebaseMessaging();
void fcmSubscribe() {
...
}
void fcmUnSubscribe() {
...
}
Future showBigPictureNotification(Map<String, dynamic> message) async {
...
var bigPictureStyleInformation = new BigPictureStyleInformation(
bigPicturePath, BitmapSource.FilePath,
contentTitle: title, summaryText: messageText);
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'', topic, messageText,
style: AndroidNotificationStyle.BigPicture,
styleInformation: bigPictureStyleInformation);
var platformChannelSpecifics =
new NotificationDetails(androidPlatformChannelSpecifics, null);
await flutterLocalNotificationsPlugin.show(
0, title, messageText, platformChannelSpecifics);
}
@override
void initState() {
super.initState();
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
currentMessage = message;
await showBigPictureNotification(currentMessage);
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
currentMessage = message;
await showBigPictureNotification(currentMessage);
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
currentMessage = message;
await showBigPictureNotification(currentMessage);
},
);
onSelectNotification(String payload) async {
await navigatorKey.currentState.push(new MaterialPageRoute(...));
}
firebaseMessaging.requestNotificationPermissions();
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
var initializationSettingsAndroid =
new AndroidInitializationSettings('ic_stat_fiber_new');
var initializationSettings =
new InitializationSettings(initializationSettingsAndroid, null);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
}
@override
Widget build(BuildContext context) {
< widget >
}
}
由于AndroidX问题,在某些依赖项的旧版本上
应用程序处于前台时的工作通知
应用程序在前台时不工作通知
感谢所有像我这样在这个问题上损失了很多时间的人。 我发送的通知有一个父“通知”对象,而它本应是“数据”对象 从这里的答案可以看出: 正如@boformer所指出的,这只适用于“通知”消息。如果您正在发送“数据”消息,则不会创建任何通知,并且消息仅通过onMessage传递。更多详细信息请参见插件自述和firebase文档
这就是为什么onMessage使用我的代码创建通知时表现得与预期一样,而onResume使用的是默认通知 您是否确保正确解析了
消息的结构?(如果您从推送通知中读取标题/正文)?Flatter firebase消息中有一个“bug”,导致onResume
和onMessage
具有不同的参数结构。顺便说一句,您知道,如果您只想显示标题/消息和图像,您可以从服务器端直接使用firebase消息进行显示,因此,您不必亲自对客户机进行操作。如果你能做到这一点,我强烈建议你走那条路线。。在Flatter中处理后台任务是一个PITA(并且不受支持),同时本地_通知与firebase消息插件的结合也存在问题。谢谢@herbert。你给我指明了正确的方向。整理好了。
flutter doctor -v
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.16299.1004], locale en-IE)
• Flutter version 1.2.1 at flutter
• Framework revision 8661d8aecd (8 weeks ago), 2019-02-14 19:19:53 -0800
• Engine revision 3757390fa4
• Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.
[√] Android Studio (version 3.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 31.1.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
[√] VS Code (version 1.32.3)
• VS Code at \AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 2.24.0
[√] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
• No issues found!
dependencies:
flutter:
sdk: flutter
http:
url_launcher: 4.2.0+3
flutter_image: ^1.0.0
path_provider: 0.4.1
flutter_downloader: 1.1.3
fluttertoast: ^2.2.11
pin_code_view: 0.1.0
image_picker: 0.4.12+1
firebase_core: 0.2.5+1
firebase_storage: 1.1.0+1
uuid: ^1.0.0
cupertino_icons: ^0.1.0
permission_handler: 1.0.1
transparent_image: 0.1.0
shared_preferences: 0.4.3
flutter_launcher_icons: ^0.7.0
firebase_messaging: 2.1.0
flutter_local_notifications: 0.4.5