android开关飞行模式的方法
2014-01-17 14:00
676 查看
android中很多场景需要判断和设置飞行模式
1.判断当前飞行模式状态:直接从Settings.Global数据库中读取飞行模式当前状态值
Settings.Global.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, STATE_DISABLED);
2.设置飞行模式状态的方法如下:
首先将飞行模式新状态写入数据库,然后发出飞行模式改变的广播;
Settings.Global.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, airplaneMode); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", STATE_ENABLED == airplaneMode); context.sendBroadcast(intent);
注:android4.1中飞行模式状态值保存在Settings.system数据库表中,但android4.2已经将该值移到Settings.Global数据库表中。android4.2上切不可使用Settings.system,不然会提示无效:
01-17 13:45:00.150: W/Settings(2972): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
相关文章推荐
- android环境不能自动生成R.java文件的问题
- Android常用调试命令、工具汇总 (一)命令篇
- Genymotion Emulator:x86架構最快速的Android模擬器,加快Android程式開
- Android4.0 修改个性化鼠标图标
- Android开源框架 Afinal简介
- Android 仿iPhone ListView拖动排序 按钮联动删除显示隐藏
- Android添加一项新的系统设置项
- Android之Canvas的save和restore
- 应用 -- 剑谍一号
- android流畅度比Ios差的原因
- android权限代码分析(四)
- Android 代码强制启动GPU渲染
- Android:真机调试,不显示logcat的解决方案
- Android WebView使用实例(html5、文件下载和远程URL)
- Android Touch事件传递机制解析 X2
- android logger with DEBUG switch
- android真机开发
- 70 Android service 进程间通信 Messenger(二)
- GreenDAO使用手册
- Android 分辨率 与计量单位