- ContentResolver cr = getContentResolver();
- if(Settings.System.getString(cr,Settings.System.AIRPLANE_MODE_ON).equals("0")){
- //获取当前飞行模式状态,返回的是String值0,或1.0为关闭飞行,1为开启飞行
- //如果关闭飞行,则打开飞行
- Settings.System.putString(cr,Settings.System.AIRPLANE_MODE_ON, "1");
- Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
- sendBroadcast(intent);
- }else{
- //否则关闭飞行
- Settings.System.putString(cr,Settings.System.AIRPLANE_MODE_ON, "0");
- Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
- sendBroadcast(intent);
- }
- //该片段来自于http://www.codesnippet.cn/detail/0501201511473.html
来源: http://www.codesnippet.cn/detail/0501201511473.html