ik0*_*024 30 gps android location android-location android-geofence
是否有可能获得用户在位置设置选项下的三种模式中选择的位置模式的信息,即
1.准确度高
2.电池节省
3.仅限GPS
我想以编程方式检查用户是否选择了高精度模式,如果没有,则自动启用它.可能吗 ?请指教.
kao*_*ick 53
从API级别19(Kitkat)开始,可以获得设备的当前位置模式:
public int getLocationMode(Context context)
{
return Settings.Secure.getInt(activityUnderTest.getContentResolver(), Settings.Secure.LOCATION_MODE);
}
Run Code Online (Sandbox Code Playgroud)
这些是可能的返回值(见这里):
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
}
Run Code Online (Sandbox Code Playgroud)
遗憾的是,您无法以编程方式设置位置模式,但您可以将用户直接发送到他可以执行此操作的设置屏幕:
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
Run Code Online (Sandbox Code Playgroud)
您可以在 LocationMamager.requestLocationUpdates 中提供条件。作为标准,您可以提供以下值之一来选择所需的精度。
Constants
int ACCURACY_COARSE A constant indicating an approximate accuracy requirement
int ACCURACY_FINE A constant indicating a finer location accuracy requirement
int ACCURACY_HIGH a constant indicating a high accuracy requirement - may be used for horizontal, altitude, speed or bearing accuracy.
int ACCURACY_LOW A constant indicating a low location accuracy requirement - may be used for horizontal, altitude, speed or bearing accuracy.
int ACCURACY_MEDIUM A constant indicating a medium accuracy requirement - currently used only for horizontal accuracy.
Run Code Online (Sandbox Code Playgroud)
请参阅 http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long , float, android.location.Criteria, android.app.PendingIntent)
| 归档时间: |
|
| 查看次数: |
23916 次 |
| 最近记录: |