简体   繁体   English

如何访问我的活动通知数据?

[英]How can I access my active notifications data?

I need to verify by an ID that comes inside the data field that I received from a firebase message.我需要通过我从 firebase 消息中收到的数据字段中的 ID 进行验证。 How can I access this field based on the active notifications?如何根据活动通知访问此字段?

The point is to remove the notification once a page with that ID is opened.重点是在打开具有该 ID 的页面后删除通知。

This is what I have to get the notifications这是我必须得到的通知

page.dart页.dart

final List<ActiveNotification>? activeNotifications =
    await flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            AndroidFlutterLocalNotificationsPlugin>()!
        .getActiveNotifications();

that gives me the body, channelId, id, title and hascode.这给了我 body、channelId、id、title 和 hascode。

While RemoteMessage message gives me a lot more stuff including a map data.虽然 RemoteMessage 消息给了我更多的东西,包括 map 数据。

Is there a way to access this data field through the ActiveNotification?有没有办法通过 ActiveNotification 访问这个数据字段?

I'm trying to do the verification with a sample on the body, but it's not a really good pratice giving the circumstances of the project.我正在尝试用身体上的样本进行验证,但考虑到项目的情况,这并不是一个很好的做法。

What I receive from firebase is sent_at (date), service_id (the id I need to get to), id (other id but not so important), body, and title.我从 firebase 收到的是 sent_at(日期)、service_id(我需要到达的 id)、id(其他 id 但不那么重要)、body 和 title。

The service_id shouldn't be displayed in the notification tho, otherwise I'd get it through the notification body service_id 不应该显示在通知中,否则我会通过通知正文获取它

Whoever answered and deleted their answer, helped my a lot.谁回答并删除了他们的答案,对我帮助很大。 So I'm marking this as the solution because it worked.所以我将其标记为解决方案,因为它有效。 Thank you stranger.谢谢陌生人。

final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
final Future<SharedPreferences> _savedNotifications =
    SharedPreferences.getInstance();

 _savedNotifications.then((saveNotifications) {
    saveNotifications.setString(
        "service_id_${message.messageId}", message.data["service_id"]);
  });

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.resumed:
        onResumed();
        break;
      case AppLifecycleState.inactive:
        onInactive();
        break;
      case AppLifecycleState.detached:
        onDetached();
        break;
      case AppLifecycleState.paused:
        onPaused();
        break;
    }
  }

  Future<String?> _getServiceId(title) async {

    _savedNotifications.then((saveNotifications) => saveNotifications.reload());
    return _savedNotifications.then((saveNotifications) {
      _savedNotifications.then(
        (value) => value.getKeys().forEach(
          (element) async {
            if (element.contains('service_id_')) {
              String serviceId = value.get(element).toString();
          }
          },
        ),
      );
    });
  }

  void onResumed() async {
    final prefs = await SharedPreferences.getInstance();
    prefs.reload();
    final List<ActiveNotification>? activeNotifications =
        await flutterLocalNotificationsPlugin
            .resolvePlatformSpecificImplementation<
                AndroidFlutterLocalNotificationsPlugin>()!
            .getActiveNotifications();

    for (ActiveNotification notification in activeNotifications!) {
      String? serviceId = await _getServiceId(notification.title);
    }
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能 terraform 授予访问我的 Azure Active Directory 租户 - How can I terraform granting access to my Azure Active Directory Tenant 我无法在任何地方访问我的数组对象,如何在 swift 中访问它们? - I cannot access my array objects anywhere, how can I access them in swift? 如何通过 Presto 访问 Google Storage 中的数据? - How can I access Data in Google Storage via Presto? 如何在验证电话号码之前访问 Firestore 数据? - How can I access firestore data before authenticating phone number? 为什么我的 streamBuilder 卡在活动连接 State 中,即使我的应用程序中有所有数据? - why my streamBuilder get stuck in the active Connection State even though i got all the data in my App? 如何为 google data studio 添加安全组以访问我的 amayon RDS? - How do I add security group for google data studio to access my amayon RDS? 从我的 Java 应用程序调用 getQueryResults 方法时,如何从 QueryResponse 访问架构? - How can I access Schema from the QueryResponse while calling getQueryResults method from my Java application? 如何访问我的 App Engine 应用程序每小时/每天/每周返回的错误数? - How can I access the number of errors that my App Engine app is returning per hour/day/week? 如何在我的 AWS REST API 访问日志中查看完整的 HTTP 请求(标头、方法、正文)? - How can I see the full HTTP request (headers, method, body) in my AWS REST API access logs? 在这种情况下,我可以为我的 react-native 应用程序使用本地通知吗? - Can I use local notifications in this case for my react-native app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM