App層
Android平台中,GPS的開啟和關閉主要在設置中:
其模式有三種:
1.High accruacy 高精度
使用GPS,Networks,Wi-Fi和Bluetooth進行定位,
准確度最好,但比較費電
2.Battery saving
使用Wi-Fi, Bluetooth和Networks進行定位,
速度快,省電,但是精度較差。
3.Device only
只使用GPS進行定位
當Location為“ON”,
Mode為“High accruacy”或者“Device Only”時,
settings數據庫location_providers_allowed字段將被修改為“network,gps”或者“gps”(修改字段的代碼LocationSettings.java中)。
1. 從settings數據庫查看location的設置模式:
adb shell settings get secure location_providers_allowed
利用上述命令得到的結果分析如下:
1) 關閉gps 結果: 空
2) 開啟gps
高精度 結果: network,gps
網絡定位: network
gps: gps
向settings數據庫寫值改變UI中Location的模式:
(1)【假如:location狀態為高精度---> network,gps】
adb shell settings put secure location_providers_allowed -network --> gps
(2) 【假如:location狀態為高精度---> network,gps】
adb shell settings put secure location_providers_allowed -gps --> 網絡定位(network)
(3) 【假如:location狀態為高精度---> network,gps】
adb shell settings put secure location_providers_allowed -network
adb shell settings put secure location_providers_allowed -gps
--> Location會執行關閉操作
(4) 在關閉location狀態下,執行
adb shell settings put secure location_providers_allowed +network -> Location打開並且模式為網絡定位
adb shell settings put secure location_providers_allowed +gps -> Location打開並且模式為gps
(5) 當location狀態為network時,執行
adb shell settings put secure location_providers_allowed +gps -> 高精度
(6) 當location狀態為gps時,執行
adb shell settings put secure location_providers_allowed +network -> 高精度
2. 從settings數據庫查看location是否使用[輔助]網絡定位network:
adb shell settings get global assisted_gps_enabled [使用服務器來輔助GPS(取消選中可降低網絡使用率)]
1) 關閉gps 結果: 0
2) 開啟gps
高精度 結果: network,gps --> 1
網絡定位: network --> 1
gps: gps --> 0
向settings數據庫寫值:
adb shell settings put global assisted_gps_enabled 0
adb shell settings put global assisted_gps_enabled 1