【问题标题】:"App is running" notification is shown using background_location plugin使用 background_location 插件显示“应用程序正在运行”通知
【发布时间】:2021-11-29 06:23:55
【问题描述】:

即使在后台,我也需要从用户那里获取位置。所以为此我使用了background_location

await BackgroundLocation.setAndroidNotification(
  title: "XXXXx",
  message: "Accessing location",
  icon: "@mipmap/ic_launcher_rounded",
);
await BackgroundLocation.startLocationService();
BackgroundLocation.getLocationUpdates((location) {
  /*print("""\n
  Latitude:  ${location.latitude}
  Longitude: ${location.longitude}
  """);*/
  if (location != null) {
    if (currentLocation == null) {
      currentLocation = loc.LocationData.fromMap(
        {
          "latitude": location.latitude,
          "longitude": location.longitude,
        },
      );
      onLocationChanged();
      return;
    }
    if (currentLocation.latitude != location.latitude ||
        currentLocation.longitude != location.longitude) {
      currentLocation = loc.LocationData.fromMap(
          {"latitude": location.latitude, "longitude": location.longitude});
      onLocationChanged();
    }
  }
});

获取位置没有问题,但此通知是不必要的。我确信当await BackgroundLocation.startLocationService(); 执行此行时会显示此通知。我们将不胜感激。

【问题讨论】:

    标签: android flutter notifications navigation geocoding


    【解决方案1】:

    插件background_location 使用foreground service 在后台获取用户的位置。

    前台服务执行的操作对于 用户。

    前台服务显示状态栏通知,以便用户 主动意识到您的应用正在前台执行任务 并且正在消耗系统资源。通知不能 除非该服务被停止或从 前景。


    您可以更改通知标题和说明,以便用户更容易理解。

    BackgroundLocation.setAndroidNotification(
        title: "Notification title",
            message: "Notification message",
            icon: "@mipmap/ic_launcher",
    );
    

    【讨论】:

    • 这不是修复..!!
    • 没有修复,如Android文档所述,如果您运行前台服务,通知是强制性的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多