概述
以下是android5.1的相关设置
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 各种系统设置的操作所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复