Android Wear - Detect if handheld GPS is enabled, prompt to enable if not

依然范特西╮ 提交于 2019-12-13 07:19:18

问题


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:

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

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*: 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.


回答1:


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

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: 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.

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?



来源:https://stackoverflow.com/questions/36068797/android-wear-detect-if-handheld-gps-is-enabled-prompt-to-enable-if-not

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!