//飞行模式打开与关闭
int isAirplaneMode = Settings.System.getInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,0);
//0关闭,1开启
Log.e("motejia", "onCreate: ++++FLY+++++"+isAirplaneMode );
//WIFI模式的打开与关闭
ConfigTest.flyStatus = isAirplaneMode;
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
int wifiState = wifiManager.getWifiState();
ConfigTest.wifiStatus = wifiState;
//0关闭中,1关闭,2打开中,3打开
Log.e("motejia", "onCreate: ++++WIFI+++++"+wifiState );
权限
<!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<!-- 这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位 -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<!-- 修改内容权限 -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
修改系统权限动态申请
//是否允许修改系统权限
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
boolean isDoing = true;
while (isDoing) {
if (!Settings.System.canWrite(context)) {
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + context.getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else {
isDoing = false;
}
}
}
|