发布于 2016-02-18 01:15:34 | 120 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


android 开发过程中如何判断当前是否是飞行模式和侦听airplane mode change,本文将以此问题详细介绍,需要了解的朋友可以参考下
Android中如何判断系统当前是否处于飞行模式中:
 
public static boolean IsAirModeOn(Context context) { 
return (Settings.System.getInt(context.getContentResolver(), 
Settings.System.AIRPLANE_MODE_ON, 0) == 1 ? true : false); 
} 

如何切换飞行模式
 
public static void setAirplaneMode(Context context, boolean enabling) { 
Settings.System.putInt(context.getContentResolver(), 
Settings.System.AIRPLANE_MODE_ON, enabling ? 1 : 0); 
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); 
intent.putExtra("state", enabling); 
context.sendBroadcast(intent); 
} 

如何注册和取消自动飞行时间
注册
 
AlarmManager am = (AlarmManager) context 
.getSystemService(Context.ALARM_SERVICE); 
Intent intent = new Intent(AIR_ALERT_ACTION); 
Parcel out = Parcel.obtain(); 
air.writeToParcel(out, 0); 
out.setDataPosition(0); 
intent.putExtra(AIR_RAW_DATA, out.marshall()); 
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 
PendingIntent.FLAG_CANCEL_CURRENT); 
am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender);取消 
AlarmManager am = (AlarmManager) context 
.getSystemService(Context.ALARM_SERVICE); 
endingIntent sender = PendingIntent.getBroadcast(context, 0, 
new Intent(action), PendingIntent.FLAG_CANCEL_CURRENT); 
am.cancel(sender); 

如何控制切换飞行模式的硬件(cell,Bluetooth,wifi)
 
Settings.System.putString(context.getContentResolver(), 
Settings.System.AIRPLANE_MODE_RADIOS, air_mode_radios);air_mode_radios为一个这样的字符串,看android源码中android/provider/Settings.java 

/*** 
* Whether Airplane Mode is on. 
*/ 
public static final String AIRPLANE_MODE_ON = "airplane_mode_on"; 
/*** 
* Constant for use in AIRPLANE_MODE_RADIOS to specify Bluetooth radio. 
*/ 
public static final String RADIO_BLUETOOTH = "bluetooth"; 
/*** 
* Constant for use in AIRPLANE_MODE_RADIOS to specify Wi-Fi radio. 
*/ 
public static final String RADIO_WIFI = "wifi"; 
/*** 
* Constant for use in AIRPLANE_MODE_RADIOS to specify Cellular radio. 
*/ 
public static final String RADIO_CELL = "cell"; 
/*** 
* A comma separated list of radios that need to be disabled when airplane mode 
* is on. This overrides WIFI_ON and BLUETOOTH_ON, if Wi-Fi and bluetooth are 
* included in the comma separated list. 
*/ 
public static final String AIRPLANE_MODE_RADIOS = "airplane_mode_radios"; 
/*** 
* A comma separated list of radios that should to be disabled when airplane mode 
* is on, but can be manually reenabled by the user. For example, if RADIO_WIFI is 
* added to both AIRPLANE_MODE_RADIOS and AIRPLANE_MODE_TOGGLEABLE_RADIOS, then Wifi 
* will be turned off when entering airplane mode, but the user will be able to reenable 
* Wifi in the Settings app. 
* 
* {@hide} 
*/ 
public static final String AIRPLANE_MODE_TOGGLEABLE_RADIOS = "airplane_mode_toggleable_radios";

如果air_mode_radios=“cell,bluetooth,wifi”,这就便是切换飞行模式是切换字符串中的这cell,bluetooth,wifi硬件,我们可以通过设置该字符串的值,来控制这三个硬件是否在切换飞行模式是进行切换状态。

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务