如何检查 wifi 定位服务是否开启...?
我正在开发一个使用用户位置的应用程序。
我可以成功要求用户启用 wifi 和 gps。 如您所知,您可以打开 WiFi,但阻止它提供您的位置。
问题是我想要求用户启用 wifi 位置获取服务(如果已禁用)。我使用 wifi 管理器来连接 wifi,使用 LOCATION_PROVIDERS_ALLOWED 来连接 GPS。两者都工作得很好。
//provider variable code
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
//i use the string into an if statement
if (!provider.contains("gps")){
}
我知道我可以将启用的提供程序放入用逗号分隔的变量中。 它工作得很好..但是“gps”是 GPS 的名称,但是字符串中 WiFi 的名称是什么???
I am working on an application that uses the location of the user.
I can successfully ask the user for wifi and gps enable.
As you know you can have WiFi on but prevent it from providing your location.
The thing is i want to ask the user to enable the wifi location obtain service if it is disabled. I use a wifi manager for wifi and a LOCATION_PROVIDERS_ALLOWED for GPS.And both work great.
//provider variable code
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
//i use the string into an if statement
if (!provider.contains("gps")){
}
And i understand that i can get enabled providers into a variable separated with comma.
It works great..but "gps" is the name for GPS but what is the name for WiFi into the string???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两个提供商。一是GPS,二是网络,包括Wifi和手机信号塔。
因此,如果两个提供商都启用,您得到的响应是
network,gps
There are two providers. One is GPS, the other is called network, and includes Wifi and cell towers.
So if both providers are enabled, the response you get is
network,gps