在最新版本Android 11和12上不断运行背景服务

发布于 2025-02-09 03:35:37 字数 234 浏览 3 评论 0原文

我搜索了很多谷歌搜索,并在过度堆栈流量上进行搜索,在移动模式下移动时,我没有得到任何适当的解决方案。

我还使用了工作经理周期性 请求,但其最小间隔为15分钟,然后如何获得位置。

我正在研究React Native Tracking项目,我创建了一个用于运行服务的本机模块。但是我的服务在背景模式下进行了一段时间。但是在从事近景服务的过程中。

如果任何人在移动版本11和12上使用背景位置更新。

谢谢

I googled a lot and search also on a over stack flow i did not get any proper solution for Continously location update when mobile on background mode.

I have also use workmanager Periodic
request but its Minimum interval is 15 minute then how get the location get sceconds.

I am working on react native tracking project i have create a native module for run services. but my service killed after sometime in background mode. but in working on forground service .

If any one use background location updates on mobile version 11 and 12 .Let me know and also share github link or code.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

走过海棠暮 2025-02-16 03:35:37

您只能使用前景服务进行连续的背景位置。背景服务不是为此。请参阅有关如何创建和使用前景服务的链接: https:// https://developer.android.android.android.android .com/指南/组件/前景服务

You can only take continuous background location using Foreground service. Background service are not meant for this. Refer this link on how to create and use a foreground service: https://developer.android.com/guide/components/foreground-services

蛮可爱 2025-02-16 03:35:37

检查此反应库无需创建自定义的本机模块,请检查: reaction-norefort-地理位置服务

为什么要使用此库

创建此库是为了尝试通过反应本机的当前地理位置API来解决Android上的位置超时问题。该库试图通过使用Google Play服务的新FusedLocationProviderClient API来解决该问题,Google强烈建议您使用Android的默认框架位置API。它会自动决定根据您的请求配置使用哪个提供商,并且还会提示您如果不满足您当前的请求配置,请更改位置模式。

用法:

...
import Geolocation from 'react-native-geolocation-service';
...

componentDidMount() {
  if (hasLocationPermission) {
    Geolocation.getCurrentPosition(
        (position) => {
          console.log(position);
        },
        (error) => {
          // See error code charts below.
          console.log(error.code, error.message);
        },
        { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
    );
  }
}

edit

您可以使用 watch置

Geolocation.watchPosition(
(position) => {
  console.log(position);
},
(error) => {
  // See error code charts below.
  console.log(error.code, error.message);
},
{ enableHighAccuracy: true, interval: 1000 }

);

上面的代码具有Interval watchPosition的参数设置为1秒,因此它将获得更新活动的位置更新(仅Android)
请记住要停止所有这些观察者。

Check this React-native library no need to create custom native modules , check : react-native-geolocation-service

Why should you use this library

This library is created in an attempt to fix the location timeout issue on android with the react-native's current implementation of Geolocation API. This library tries to solve the issue by using Google Play Service's new FusedLocationProviderClient API, which Google strongly recommends over android's default framework location API. It automatically decides which provider to use based on your request configuration and also prompts you to change the location mode if it doesn't satisfy your current request configuration.

Usage:

...
import Geolocation from 'react-native-geolocation-service';
...

componentDidMount() {
  if (hasLocationPermission) {
    Geolocation.getCurrentPosition(
        (position) => {
          console.log(position);
        },
        (error) => {
          // See error code charts below.
          console.log(error.code, error.message);
        },
        { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
    );
  }
}

Edit:

you could use watchPosition

Geolocation.watchPosition(
(position) => {
  console.log(position);
},
(error) => {
  // See error code charts below.
  console.log(error.code, error.message);
},
{ enableHighAccuracy: true, interval: 1000 }

);

above code has interval param of the watchPosition is set to 1 sec so it will get update active location updates (android only)
remember to stop all these observers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文