在Android上的Qt定位

Qt Positioning on Android

在Android上的Qt定位

Using Qt Positioning from Android Services

使用Android服务的Qt定位

Using Qt Positioning from a service requires several extra actions to be taken, depending on the Android version. The sections below give more details on these actions.

根据Android版本的不同,从服务中使用Qt定位需要采取几个额外的操作。以下部分将详细介绍这些操作。

Note: Since Android 8 (API level 26), the OS limits how frequently an application can retrieve the user's current location while running in the background. The application will normally be able to receive location updates only a few times each hour. For more information, see Background Location Limits.


注:由于Android 8(API 26级),操作系统限制了应用程序在后台运行时检索用户当前位置的频率。应用程序通常每小时只能接收几次位置更新。有关详细信息,请参见背景位置限制。

Using Foreground Service

使用前台服务

Since Android 8 (API level 26), the background service can be killed by the Android OS when the application goes to the background. This normally happens after around a minute of running in the background. To keep the location service running, the service should be implemented as a Foreground Service. Such service shows a status bar notification, which cannot be dismissed until the service is stopped or removed from the foreground. This allows the user to be always aware of the important background activities.

​由于Android 8(API 26级),当应用程序进入后台时,后台服务可以被Android操作系统杀死。这通常发生在后台运行约一分钟后。为了保持位置服务的运行,该服务应作为前台服务实现。此类服务显示状态栏通知,在服务停止或从前台删除之前,该通知无法被解除。这允许用户始终了解重要的后台活动。

Note: Since Android 9 (API level 28), foreground services require a special FOREGROUND_SERVICE permission. See the Android documentation for more details on implementing foreground services.

注:由于Android 9(API 28级),前台服务需要特殊的FOREGROUND_SERVICE 权限。有关实现前台服务的更多详细信息,请参阅Android文档。

Use Background Location Permission

使用背景位置权限

Since Android 10 (API level 29), the service must request the ACCESS_BACKGROUND_LOCATION permission. It should be added to the AndroidManifest.xml file as follows:

​由于Android 10(API级别29),服务必须请求ACCESS_BACKGROUND_LOCATION权限。它应该添加到AndroidManifest.xml文件中,如下所示:

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

Note: Once the permission is added to AndroidManifest.xml, it is still required to explicitly allow the constant access to the location services for the application. To do it, one should navigate to Settings -> Apps, select a proper application, open its permissions, and specify the Allow all the time permission for Location (see the screenshot below).

注意:一旦将权限添加到AndroidManifest.xml中,仍然需要明确允许应用程序对位置服务的持续访问。为此,应该导航到“设置”->“应用程序”,选择一个合适的应用程序,打开其权限,并为“位置”指定“允许所有时间”权限(请参阅下面的屏幕截图)。

Check Access Location in the Background Android documentation for more details.

​有关更多详细信息,请查看后台Android文档中的访问位置。

Interfaces between C++ and QML CodeiOS support

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值