教你如何控制手机, 开启飞行模式,控制gps开关,控制数据浏览开关

下列命令建立在su权限之上.
请支持原创谢谢.

adb shell svc data enable/disadle //操作数据开关

adb shell settings put secure location_providers_allowed gps,network //操作gps提供者 假如设置其他关键字,导致gps关闭.

对于sdk >=23 6.0 系统操作gps提供者需要'+','-'

adb shell settings put secure location_providers_allowed +gps,-network6.0系统操作gps开关

1: adb shell pm grant com.example.aplication.teste android.permission.WRITE_SECURE_SETTINGS 使用pm命令让程序获得系统权限.

2:

3: 直接操作gps开关. 1,2步没有完成是不能够操作gps开关的.

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代表关闭

1代表开启

数据流量

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

你可能感兴趣的:(教你如何控制手机, 开启飞行模式,控制gps开关,控制数据浏览开关)