标签:androi bean dbr putextra ati android root权限 roo ble
Android 4.2 之后 系统不予许第三方软件去设置飞行模式,除非你的app是系统应用,得到了root权限
//获取当前的飞行模式状态 需要根据不同的Android版本进行修改
@SuppressWarnings("deprecation")
public boolean isAirplaneModeOn()
{
//4.2以下
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
{
return Settings.System.getInt(getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
}
else //4.2或4.2以上
{
return Settings.Global.getInt(getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
}
//设置飞行模式
@SuppressWarnings("deprecation")
public void setAirplaneModeOn(boolean isEnable)
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
{
Settings.System.putInt(getContentResolver(),
Settings.System.AIRPLANE_MODE_ON,isEnable ? 1:0);
}
else //4.2或4.2以上
{
Settings.Global.putInt(getContentResolver(), Global.AIRPLANE_MODE_ON, isEnable? 1 : 0);
}
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", isEnable);
sendBroadcast(intent);
}
需要注意的是,在4.2上其实App是没有权限修改Setting.Global的,解决办法是把你的App放到系统的system/app目录下,然后install。这样一来,App成为system app,可以获得写Setting.Global的权限。。
标签:androi bean dbr putextra ati android root权限 roo ble
原文地址:http://www.cnblogs.com/ganchuanpu/p/6792952.html