通过Android以编程方式启用GPS(无需导航至位置设置) [英] Enable GPS programmatically Android (without navigating to the location settings)

查看:197
本文介绍了通过Android以编程方式启用GPS(无需导航至位置设置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过编程方式启用GPS(就像在正式的Google Maps应用中一样),只需点击弹出屏幕上的打开"选项即可(无需导航至位置设置)?

How 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)?

推荐答案

Google Maps应用正在使用我们现在可以使用的功能

The Google Maps app is using what is now available to us as SettingsApi 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并不是特别简单.在此一个示例应用.正如Laurenswuyts的答案所建议的那样,使用ACTION_LOCATION_SOURCE_SETTINGS更容易实现.

Using SettingsApi is not especially simple. Here a sample app for that. Using ACTION_LOCATION_SOURCE_SETTINGS, as suggested in Laurenswuyts' answer, is much simpler to implement.

这篇关于通过Android以编程方式启用GPS(无需导航至位置设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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