下列命令建立在su權(quán)限之上.
請(qǐng)支持原創(chuàng)謝謝.
adb shell svc data enable/disadle //操作數(shù)據(jù)開(kāi)關(guān)
adb shell settings put secure location_providers_allowed gps,network //操作gps提供者 假如設(shè)置其他關(guān)鍵字,導(dǎo)致gps關(guān)閉.
對(duì)于sdk >=23 6.0 系統(tǒng)操作gps提供者需要'+','-'
adb shell settings put secure location_providers_allowed +gps,-network6.0系統(tǒng)操作gps開(kāi)關(guān)
1: adb shell pm grant com.example.aplication.teste android.permission.WRITE_SECURE_SETTINGS 使用pm命令讓程序獲得系統(tǒng)權(quán)限.
2:<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
3: 直接操作gps開(kāi)關(guān). 1,2步?jīng)]有完成是不能夠操作gps開(kāi)關(guān)的.
private void openGPSSettings() {
//Get GPS now state (open or closed)
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER);
if (gpsEnabled) {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, 0);
} else {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, 3);
}
}
一般情況下:
0代表關(guān)閉
1代表開(kāi)啟
數(shù)據(jù)流量
adb shell svc data enable|disable
飛行模式
Turn on:
settings put global airplane_mode_on 1
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true
Turn off:
settings put global airplane_mode_on 0
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false