- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
当应用在前景时,我会收到通知,而不是在后台应用程序时收到通知。另外,我有2个小时或更长时间的Google-ed/stackoverflow-ed,但能够解决这个问题。
My Configurations are :
firebase_auth: ^0.10.0
firebase_messaging: ^5.0.0
The manifest is like this:
The code is like this:
final notifications = new FirebaseMessaging();
class AppNotifications {
static String fcmToken = '';
static Future<Null> init() async {
appLogs("AppNotifications init");
notifications.requestNotificationPermissions(const IosNotificationSettings(sound: true, badge: true, alert: true));
await configure();
fcmToken = await notifications.getToken();
appLogs("FCM TOKEN : " + fcmToken);
notifications.onTokenRefresh.listen((newToken) {
fcmToken = newToken;
appLogs("FCM TOKEN onTokenRefresh: " + fcmToken);
});
await updateFCMToken();
}
static Future<Null> configure() async {
appLogs("AppNotifications Configure");
notifications.configure(onMessage: (msg) {
appLogs('FCM onMessage: ' + msg.toString());
}, onLaunch: (lun) {
appLogs('FCM onLaunch: ' + lun.toString());
}, onResume: (res) {
appLogs('FCM onResume: ' + res.toString());
});
}
static Future<Null> updateFCMToken() async {
auth.currentUser.fcmToken = fcmToken;
await updateUserInSharedPreference();
}
}
I am calling the function like this:
class HomeScreenState extends State<HomeScreen> {
@override
void initState() {
super.initState();
Future.delayed(Duration(milliseconds: 100), () async {
await AppNotifications.init();
});
}
..... ....
I am using postman for sending the notification :
My logs :
**(App is Foreground)** I/flutter (31888): APPLOGS : FCM onMessage: {notification: {title: Test notification title, body: Test notification body}, data: {status: done, id: 1, foo: bar, click_action: FLUTTER_NOTIFICATION_CLICK}}
**(App is Background)** W/FirebaseMessaging(31888): Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
Flutter doctor :
[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.4 18E226, locale en-GB)
• Flutter version 1.2.1 at /Users/Ajay/SDK/flutter
• Framework revision 8661d8aecd (3 months 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 /Users/Ajay/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.2.1, Build version 10E1001
• ios-deploy 1.9.4
• CocoaPods version 1.6.0
[✓] Android Studio (version 3.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 34.0.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
[!] VS Code (version 1.33.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (1 available)
• ONEPLUS A5000 • b47e8396 • android-arm64 • Android 9 (API 28)
最佳答案
lost my 2 days to fix this issue, it may helpful for you.notification tag only for showing notification. you can access only data content on onResume/onLaunch.
If you want handle notification message inside onResume/onLaunch add those messages in data tag also, Then you can do what ever you want.
refer more detail on this link
发送此通知消息
{
"notification": {
"body": "body",
"title": "title"
},
"priority": "high",
"data": {
"body": "body",
"title": "title"
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"id": "1",
"status": "done",
"image": "https://ibin.co/2t1lLdpfS06F.png",
},
"to": <your token>
}
you will receive below information onResume or onLaunch, your notification tag will be empty here
{notification: {}, data: {image: https://ibin.co/2t1lLdpfS06F.png, google.original_priority: high, google.sent_time: 1560858283888, google.delivered_priority: high, body: body , title: title, click_action: FLUTTER_NOTIFICATION_CLICK, google.message_id: 0:1560858283908500%eefdc741eefdc741, collapse_key: <package>, google.ttl: 2419200, from: <from>, id: 1, status: done}}
you can use title and body which is added in data tag.
关于flutter - firebase_messaging onResume 和 onLaunch 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56025164/
假设我有 3 个 Fragment,BaseFragment,以及第一个 fragment 和第二个 fragment 。 我已经实现了 BaseFragment 的 onResume() 并编写了一
这是我的第一个应用程序,所以这个问题/答案可能非常基本。我目前有 onPause(); ,当玩家离开屏幕时停止播放音乐。我尝试做类似的事情,但使用 onResume,以便再次播放音乐(backgrou
如何重载onResume()以正确的方式工作?我想从 activity 返回到 MainActivity ,我希望在其中具有与应用程序启动后相同的状态。我想使用 recreate() 但它循环了或者类
出于某种原因,当我在代码中声明 onResume() 时,它会无缘无故地让我的程序崩溃,甚至无法打开。 这是我的 onResume() 代码: public void onResume() {
我遇到了一个棘手的问题。我有两个标签页主机 ...标签页主机 A 和标签页主机 B。每个选项卡主机都有三个选项卡(我们称它们为 A1、B1、A2、B2 等)。 选项卡主机 B 从 Activity A
我的应用程序有一个问题,如果我返回到一个 Activity ,我会收到一条错误消息,指出数据库已关闭: ERROR/AndroidRuntime(3566): Caused by: java.lang
在我的 android 应用程序中,我有一个问题已经 3 天无法解决了。我阅读了很多帖子和答案,但仍然找不到我的解决方案。 我的问题是当我按下主页按钮并在很长时间后返回应用程序时它崩溃了(NullPo
我如何实现一个无限滚动到 onResume(),目前是 onCreateView,我实现了一个无限滚动,它工作得很好,但是当涉及到 onResume() 时,它在另一个显示空白数据时不起作用。 这是o
我在我的 Android 应用程序中使用谷歌地图。一切都很好,但是当我没有启用 GPS 服务时,我会显示一条消息来启用。当我启用 GPS 并在我的 Fragment der map 中返回时,仅当我按
我一直在搜索这个,但不知道会发生什么...... 当我回到上一个 Activity 时,我的组件已正确初始化,但它们上面有一个新组件... 我的意思是,在 Debug模式下,我遵循并执行了 onRes
我读过一些与我的问题相似的帖子,最相似的问题在这里:Strange onPause(), onResume() behaviour in fragments 我正在使用 FragmentPagerAd
我已经阅读了关于 onResume() 和 onStart() 的文档,但我仍然不明白的一件事是 onResume() 在没有 onStart() 之前被调用? 最佳答案 请引用Android Act
我正在尝试制作一个简单的记事本应用程序,我想在“新建笔记” Activity 完成且主屏幕恢复时刷新笔记。但是,当我尝试使用此代码打开应用程序时,我会强制关闭。如果我删除 OnResume 东西,它不
这个问题在这里已经有了答案: Android: Under what circumstances would a Dialog appearing cause onPause() to be cal
我有一个问题。在为预览初始化相机并将另一个应用程序聚焦后,然后返回我的应用程序:预览显示为黑色。如果我继续拍照,它会拍摄我正常指向相机的位置的照片。 我在 OnResume() 覆盖上做错了什么吗?相
我正在使用列表适配器来显示不同的商店,当有人选择商店时,它会将他们带到一个新的 Activity 中,他们可以在该 Activity 中将商店添加到该屏幕上的收藏夹。 有一个调用 finish();
我有一个 Intent,它通过一个长的 Extra 从我的数据库中获取信息。它还通过 String Extra 设置 Activity 的标题。 现在,当我第一次启动 Activity 时,一切都完美
所以我有我的主要 Activity ,当您按下按钮时,它会启动 Activity 2。启动 activity2 后,我按下主页按钮,它将在 activity2 触发 onPause,然后 androi
我正在编写一个购物车应用,其中我允许用户选择要购买的商品并将他们需要的商品添加到购物车,为此我给出了两种不同的标签, 第一个标签,浏览产品 第二个标签,浏览购物车中的商品 [用户添加] 这里我遇到了一
我有问题。当我第一次启动我的 android 应用程序时,在主要 Activity 中 onCreate 和 onResume 都会被调用。但我只想被称为 onCreate。 我能做什么? 最佳答案
我是一名优秀的程序员,十分优秀!