Android Wear - 检测手持GPS是否开启,未开启则提示开启 [英] Android Wear - Detect if handheld GPS is enabled, prompt to enable if not

查看:32
本文介绍了Android Wear - 检测手持GPS是否开启,未开启则提示开启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为 Android Wear 构建一个应用程序,只有在启用了手持设备上的 GPS 的情况下,用户才能编辑一些设置.我想知道是否可以通过在 Smartwatch 上请求许可来以编程方式启用 GPS,而不必将用户重定向到手持设备的屏幕来接受或拒绝请求.

I'm currently building an application for Android Wear where the user can edit some settings only if the GPS on the handheld is enabled. I'm wondering whether I can enable the GPS programatically by asking permission on the Smartwatch, instead of having to redirect the user to the handheld's screen to accept or decline the request.

我创建了以下模型来说明我想要完成的流程:

I created the following mockup to illustrate the flow that I want to accomplish:

我有以下问题,我还在图像中添加了 1* 和 2* 以说明我的问题适用的位置:

I have the following questions, I have also added a 1* and 2* to the image to illustrate where my question applies:

1*: 是否可以检查智能手表是否启用了手持 GPS?如果不是,我是否必须向手持设备构建自定义请求,检查手持设备的可用性并自己向智能手表返回 true 或 false?

1*: Is it possible to check whether the handheld GPS is enabled on the Smartwatch? If not, do I have to construct a custom request to the handheld, check availability on the handheld and return true or false to the smartwatch myself?

2*:这可能吗,还是我真的必须将用户重定向到他或她的手持设备才能打开 GPS?我真的找不到关于此的任何文档,但似乎 Google 会(或应该)考虑过这一点.

2*: Is this possible, or do I really have to redirect the user to his or her handheld device to turn on the GPS? I couldn't really find any documentation on this, but it would seem that Google would (or should) have thought about this.

感谢任何帮助,提前致谢.

Any help is appreciated, thanks in advance.

推荐答案

我将以相反的顺序回答你的两个问题:

I'm going to answer your two questions in reverse order:

2:您不能在没有用户同意的情况下打开 GPS - 这样做会带来安全/隐私问题 - 但您可以触发系统 UI 以获得该权限(然后打开 GPS,如果有的话).它称为 SettingsApi ,并在此 SO 帖子中进行了详细描述:如何像谷歌地图一样显示启用位置对话框?

2: You can't just turn on GPS without the user agreeing to it - doing so would have security/privacy issues - but you can trigger a system UI to get that permission (and then turn on GPS if given). It's called the SettingsApi , and is well described in this SO post: How to show enable location dialog like Google maps?

1:我有理由确定您需要将此请求转发到手持设备,并在那里显示 API.我怀疑 Wear 上是否存在系统 UI.但是 - 考虑到您无论如何都需要实现此 SettingsApi 调用 - 您可以先尝试在 Wear 上执行此操作,看看会发生什么.如果失败,您可以随时将代码移至掌上电脑.

1: I'm reasonably sure that you'll need to relay this request to the handheld, and show the API there. I doubt that the system UI exists on Wear. However - given you're going to need to implement this SettingsApi call anyway - you might try doing it on Wear first to see what happens. You can always move the code to the handheld if it fails.

另外,你有没有想过手表自带 GPS 的情况?您还需要使用手持设备的 GPS 吗?

Also, have you thought about the case where the watch has its own internal GPS? Will you still require the use of the handheld's GPS?

这篇关于Android Wear - 检测手持GPS是否开启,未开启则提示开启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆