Is it possible to get the information on the location mode which the user has selected among the three modes under the location settings options i.e

是否有可能在位置设置选项下获得用户在三种模式中选择的位置模式的信息,即

1.Hight Accuracy

2.Battery Saving

3.GPS Only

I want to programmatically check if user has selected High Accuracy mode if not then enable it automatically. Is it possible ? Please advice.

我想以编程方式检查用户是否选择了高精度模式,如果没有,则自动启用它。可能吗 ?请指教。

3 个解决方案

#1


43

It is possible to get the device's current location mode since API level 19 (Kitkat):

从API级别19(Kitkat)开始,可以获得设备的当前位置模式:

public int getLocationMode(Context context)
{
return Settings.Secure.getInt(activityUnderTest.getContentResolver(), Settings.Secure.LOCATION_MODE);

}

These are the possible return values (see here):

这些是可能的返回值(见这里):

0 = LOCATION_MODE_OFF
1 = LOCATION_MODE_SENSORS_ONLY
2 = LOCATION_MODE_BATTERY_SAVING
3 = LOCATION_MODE_HIGH_ACCURACY

0 = LOCATION_MODE_OFF 1 = LOCATION_MODE_SENSORS_ONLY 2 = LOCATION_MODE_BATTERY_SAVING 3 = LOCATION_MODE_HIGH_ACCURACY

So you want something like

所以你想要的东西

if(getLocationMode(context) == 3)
{
// do stuff
}

Unfortunately you can't set the location mode programmatically but you can send the user directly to the settings screen where he can do that:

遗憾的是,您无法以编程方式设置位置模式,但您可以将用户直接发送到他可以执行此操作的设置屏幕:

startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

更多相关文章

  1. 【Based Android】android通过criteria选择合适的地理位置服务
  2. Settings点击Location(位置)后右上角的开关button不会消失
  3. Android(监听+回调=观察者)模式从Dialog到Activity传递数据
  4. 在android上滚动时,列表视图的位置会发生变化
  5. Android全屏模式,沉浸模式。粘性沉浸模式
  6. DialogFragment自定义dialog的位置和大小
  7. 【Android】策略模式封装百度地图路线规划模块
  8. Android中的模式:Builder模式的优点赏析
  9. 单例模式----设计模式系列

随机推荐

  1. PHP 网站模板核心类
  2. 如何在php数组中获取php键值
  3. WordPress注册和用户注册是分开的
  4. Php简单的html dom删除特定类的div
  5. 豆瓣的账号登录及api操作
  6. cenos下配置Apache+PHP最新版7.1.6+MySQL
  7. Thinkphp MVC以及4种url放文方式
  8. 带有wamp的intl扩展名php_intl.dll
  9. PHP 源码加密! 求神拜佛,求各位大虾了。
  10. PHP编程调试方法总结