启用GPS编程机器人(无导航到位置设置) [英] Enable GPS programatically Android (without navigating to the location settings)
问题描述
这可能是一个非常普遍的问题,但必须有一个以编程方式启用GPS,因为它仅通过点击打开选项,弹出屏幕上出现在官方的谷歌地图应用程序(不导航到位置设置)。 有人可以帮忙吗?
This might be a very common question, however there has to be a way to enable GPS programmatically, as it does happen in the official Google Maps app by just clicking on the 'turn on' option on the pop up screen (without navigating to location settings). Can someone help?
推荐答案
在谷歌地图应用程序使用的是现在提供给我们的为 SettingsApi
在播放服务SDK的7.0.0。您可以使用 SettingsApi
来询问是否您需要的 LocationRequest
可实现与任何位置启用提供商。如果无法实现,即用服务认为用户可以改变这一点,你可以要求你看到的地图显示弹出对话框。
The Google Maps app is using what is now available to us as SettingsApi
in 7.0.0 of the Play Services SDK. You can use SettingsApi
to inquire as to whether your desired LocationRequest
can be fulfilled with whatever location providers are enabled. If it cannot be fulfilled, and Play Services thinks that the user can change this, you can ask for the dialog that you see Maps display pop up.
使用 SettingsApi
不是特别简单的。我刚刚张贴一个示例应用程序了解,昨天,从版本6.6 我的书。使用 ACTION_LOCATION_SOURCE_SETTINGS
,如Laurenswuyts的回答暗示,是的多的容易实现。
Using SettingsApi
is not especially simple. I just posted a sample app for that yesterday, from Version 6.6 of my book. Using ACTION_LOCATION_SOURCE_SETTINGS
, as suggested in Laurenswuyts' answer, is much simpler to implement.
这篇关于启用GPS编程机器人(无导航到位置设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!