android 各种系统设置的操作
2016-11-06 10:18
781 查看
以下是android5.1的相关设置
一般默认情况下,飞行模式是关闭的。
获取飞行模式的状态,
设置飞行模式的状态,
设置完了之后不要忘记发出飞行模式改变了的粘性广播,因为很多地方需要根据飞行模式的状态来调整行为。
设置数据业务是否可用,调用以下方法就可以了;输入参数enabled为true表示打开数据业务,否则关闭数据业务,
当然,前提必须得有张SIM卡才可以使用数据业务。
比如现在想将语言设置为中文,在该list中,已知中文是第30个,
那么可以直接调用updatelanguge(29)完成语言的设置。
最后,不要忘记了,在AndroidManifest.xml 文件中添加对应的权限。
1,飞行模式的设置
private int mModel; private static final int AIRPLANE_OFF= 0; // 飞行模式关闭 private static final int AIRPLANE_ON = 1; // 飞行模式打开
一般默认情况下,飞行模式是关闭的。
获取飞行模式的状态,
mModel = Settings.Global.getInt(getContentResolver(),Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
设置飞行模式的状态,
Settings.Global.putInt(getContentResolver(),Settings.Global.AIRPLANE_MODE_ON, mModel);
设置完了之后不要忘记发出飞行模式改变了的粘性广播,因为很多地方需要根据飞行模式的状态来调整行为。
Intent intent = new Intent("android.action.SETTING_AIRPLANE_MODE_UPDATE"); intent.putExtra("state", mModel == AIRPLANE_ON ? true : false); sendStickyBroadcast(intent);
2,数据业务的开/关设置
首先判断是否有在使用数据业务private TelephonyManager sTelephonyManager = null; private SubscriptionInfo sir; sTelephonyManager =(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); sir = getsir(); if (!sTelephonyManager.getDataEnabled()) { // 说明未使用数据业务 } else if (sir != null) { // 说明当前正在使用数据业务 } private SubscriptionInfo getsir() { int subId = SubscriptionManager.getDefaultDataSubId(); final List<SubscriptionInfo> subInfoList = SubscriptionManager.from(this).getActiveSubscriptionInfoList(); if (subInfoList != null) { final int subInfoLength = subInfoList.size(); for (int i = 0; i < subInfoLength; ++i) { final SubscriptionInfo sir = subInfoList.get(i); if (sir != null && sir.getSubscriptionId() == subId) { return sir; } } } return null; }
设置数据业务是否可用,调用以下方法就可以了;输入参数enabled为true表示打开数据业务,否则关闭数据业务,
private void setMobileDataEnabled(boolean enabled) { if (sTelephonyManager != null) { int[] sub1Id = SubscriptionManager.getSubId(PhoneConstants.SUB1); sTelephonyManager.setDataEnabled(sub1Id[0], enabled); int[] sub2Id = SubscriptionManager.getSubId(PhoneConstants.SUB2); sTelephonyManager.setDataEnabled(sub2Id[0], enabled); } }
当然,前提必须得有张SIM卡才可以使用数据业务。
3,语言设置
获取系统中所有的语言,存放在list中,private List<LocalePicker.LocaleInfo> locales; locales = LocalePicker.getAllAssetLocales(this, false); // 获取所有语言 Collections.sort(locales); // 按照字母进行排序
比如现在想将语言设置为中文,在该list中,已知中文是第30个,
那么可以直接调用updatelanguge(29)完成语言的设置。
public void updatelanguge(int position) { int mm = 0; LocalePicker.LocaleInfo mlacal = null; for (LocalePicker.LocaleInfo locale : locales) { mlacal = locale; if(mm == position){ break; } mm++; } final Locale locale = mlacal.getLocale(); LocalePicker.updateLocale(locale); }
4,恢复出厂设置
恢复出厂设置直接发送一个广播就可以了,Intent intent = new Intent("android.intent.action.MASTER_CLEAR"); intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); sendBroadcast(intent);
最后,不要忘记了,在AndroidManifest.xml 文件中添加对应的权限。
相关文章推荐
- android开发 打开各种系统设置信息页面 android.settings
- android如何设置系统闹钟,解决应用全局范围内定时的操作
- android系统各种音量的获取与设置
- android 获取系统中各种类型音量及对音量设置
- android笔记:android系统各种音量的获取与设置
- Android 使用系统Api设置系统各种属性(持续更新,欢迎讨论)
- android系统设置应用详情页存储项各种大小的意义
- android系统各种音量的获取与设置
- Android之数据存储共享参数实现系统设置操作功能(二)
- android 获取系统中各种类型音量及对音量设置
- android 获取系统中各种类型音量及对音量设置
- android系统各种音量的获取与设置
- Android 自动跳转到各种系统设置界面
- android开发 打开各种系统设置信息页面
- android系统各种音量的获取与设置
- [转]android系统各种音量的获取与设置
- android系统各种音量的获取与设置