以编程方式将位置模式更改为高精度Android [英] Change Location Mode to High Accuracy Programmatically Android

查看:197
本文介绍了以编程方式将位置模式更改为高精度Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

1.高精度

p>

2.电池节省

3.仅限GPS



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

解决方案

可以从 API级别19(Kitkat)获取设备的当前位置模式。 strong>:

  public int getLocationMode(上下文上下文)
{
return Settings.Secure.getInt( activityUnderTest.getContentResolver(),Settings.Secure.LOCATION_MODE);




这些是可能的返回值(请参阅这里):



0 = LOCATION_MODE_OFF

1 = LOCATION_MODE_SENSORS_ONLY

2 = LOCATION_MODE_BATTERY_SAVING

3 = LOCATION_MODE_HIGH_ACCURACY



所以你想要类似于

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

不幸的是,您不能以编程方式设置位置模式,但您可以直接将用户发送到设置屏幕,他可以这样做:

  startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) ; 


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.

解决方案

It is possible to get the device's current location mode since API level 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

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));

这篇关于以编程方式将位置模式更改为高精度Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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