Android LocationManager:Android 12 中的意外行为

发布于 2025-01-09 02:57:12 字数 584 浏览 1 评论 0原文

现场用户报告了应用程序中 GPS 位置的随机问题。 该应用程序使用 LocationManager 已有大约 12 年,几乎没有进行任何修改。

通过在运行 Android 12 的 Pixel 3 上进行测试,我发现了一些不可预测的行为。 该行为包括位置偏离半英里,以及不定期更新,除非其他应用程序使用 GPS。

Android 11/12 中的位置管理器是否有一些不同之处? 如果是的话,它们记录在哪里? 我的代码从 Android 1.5 开始就运行良好。

我通过一个库使用它,但是反编译给了我这个调用:

mLocationManager.requestLocationUpdates("gps", 250, 1, listener);

我将其更改为

   mLocationManager.requestLocationUpdates("gps", 100, 0, listener);

它工作了一段时间,然后再次停止工作。 更新没有进来。

即使文档说我不需要后台位置来在活动或前台服务中使用位置,它是否需要后台位置?

如果不是,那到底是怎么回事?

Users in the field are reporting random problems with GPS location in an app.
The app has been using LocationManager for about 12 years with little modification.

I was able to see some unpredictable behavior by testing on Pixel 3 with Android 12.
The behavior includes location being off by half a mile, and not updating regularly unless some other app uses GPS.

Are there some things that are different about location manager in Android 11/12?
If so where are they documented?
The code I have has worked fine since Android 1.5.

I am using it through a library, but decompiling gave me this call:

mLocationManager.requestLocationUpdates("gps", 250, 1, listener);

I changed it to

   mLocationManager.requestLocationUpdates("gps", 100, 0, listener);

It worked for a bit and then stopped working again.
The updates don't come in.

Does it need background location even though the documentation says I SHOULDN'T need background location to use location in an activity or foreground service?

If not, what the heck is going on?

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

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

发布评论

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

评论(2

折戟 2025-01-16 02:57:12

我们已经看到了同样的问题@nathanMDT,我们最初使用我们认为有问题的 SDK 记录了该问题,链接如下。问题出在 Android 12 上,他们大约一个月前对一些谷歌地图权限进行了更改,所有相关文章都可以在下面的帖子中找到。开发人员大约 3 天前在此跟踪器中发布了更新,我希望这会有所帮助。第一个回应是“等到 Android 13”。顺便说一句,降级到 Android 11 会立即修复更新频率 - 但这并没有多大帮助。

https://issuetracker.google.com/issues/215186921?pli=1

https://github.com/mapbox/mapbox-unity-sdk/issues/1850

Weve seen the same problem @nathanMDT which we logged initially with the SDK we thought was at fault, link below. The problem is Android 12 specifically and a change they made about a month ago to some google map permissions, all the relevant articles can be found in the below post. The devs dropped an update about 3 days ago in this tracker which im hoping will help. First response was "wait till Android 13". As a side note downgrading to Android 11 instantly fixes the frequency updates - not that this helps much.

https://issuetracker.google.com/issues/215186921?pli=1

https://github.com/mapbox/mapbox-unity-sdk/issues/1850

乜一 2025-01-16 02:57:12

前台服务仍然需要后台位置权限才能访问位置。这是因为它对用户来说并不明显,只是因为那里有一条通知表明它仍在使用 GPS。是的,这是在 Android 11 中添加的: https:// developer.android.com/guide/components/foreground-services#bg-access-restrictions

Foreground services still require background location permissions to access location. That's because its non obvious to the user that just because there's a notification there that it's still using GPS. And yes, this was added in Android 11: https://developer.android.com/guide/components/foreground-services#bg-access-restrictions

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