android 如何判斷當(dāng)前是否為飛行模式
更新時(shí)間:2012年11月23日 15:30:09 作者:
android 開發(fā)過程中如何判斷當(dāng)前是否是飛行模式和偵聽airplane mode change,本文將以此問題詳細(xì)介紹,需要了解的朋友可以參考下
Android中如何判斷系統(tǒng)當(dāng)前是否處于飛行模式中:
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);
}
如何注冊和取消自動飛行時(shí)間
注冊
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為一個(gè)這樣的字符串,看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硬件,我們可以通過設(shè)置該字符串的值,來控制這三個(gè)硬件是否在切換飛行模式是進(jìn)行切換狀態(tài)。
復(fù)制代碼 代碼如下:
public static boolean IsAirModeOn(Context context) {
return (Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) == 1 ? true : false);
}
如何切換飛行模式
復(fù)制代碼 代碼如下:
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);
}
如何注冊和取消自動飛行時(shí)間
注冊
復(fù)制代碼 代碼如下:
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)
復(fù)制代碼 代碼如下:
Settings.System.putString(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_RADIOS, air_mode_radios);air_mode_radios為一個(gè)這樣的字符串,看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硬件,我們可以通過設(shè)置該字符串的值,來控制這三個(gè)硬件是否在切換飛行模式是進(jìn)行切換狀態(tài)。
您可能感興趣的文章:
- Android主題切換之探究白天和夜間模式
- AndroidSDK Support自帶夜間、日間模式切換詳解
- Android夜間模式最佳實(shí)踐
- android基礎(chǔ)教程之夜間模式實(shí)現(xiàn)示例
- javascript判斷iphone/android手機(jī)橫豎屏模式的函數(shù)
- Android 聽筒模式的具體實(shí)現(xiàn)實(shí)例
- Android開發(fā)之文件操作模式深入理解
- Android 情景模式的設(shè)置代碼
- Android 如何定制vibrator的各種震動模式M 具體方法
- 三行Android代碼實(shí)現(xiàn)白天夜間模式流暢切換
相關(guān)文章
Android開發(fā)中TextView文本過長滾動顯示實(shí)現(xiàn)方法分析
這篇文章主要介紹了Android開發(fā)中TextView文本過長滾動顯示實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Android項(xiàng)目開發(fā)中TextView顯示超長文本的具體操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-02-02
Android 加載大圖、多圖和LruCache緩存詳細(xì)介紹
這篇文章主要介紹了Android 加載大圖、多圖和LruCache緩存詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2016-10-10
Android編程判斷網(wǎng)絡(luò)連接是否可用的方法
這篇文章主要介紹了Android編程判斷網(wǎng)絡(luò)連接是否可用的方法,實(shí)例分析了Android判定網(wǎng)絡(luò)連接的相關(guān)技巧與實(shí)現(xiàn)步驟,需要的朋友可以參考下2015-12-12
Android實(shí)現(xiàn)通過手勢控制圖片大小縮放的方法
這篇文章主要介紹了Android實(shí)現(xiàn)通過手勢控制圖片大小縮放的方法,結(jié)合實(shí)例形式分析了Android控制圖片縮放的原理、實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下2016-10-10
Android自定義View實(shí)現(xiàn)QQ運(yùn)動積分轉(zhuǎn)盤抽獎功能
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)QQ運(yùn)動積分轉(zhuǎn)盤抽獎功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
Android獲取手機(jī)安裝應(yīng)用程序的詳細(xì)信息
在開發(fā)Android應(yīng)用時(shí),有時(shí)我們需要獲取設(shè)備上已安裝的所有應(yīng)用程序的信息,這篇文章為大家整理了一些常用的方法,希望對大家有所幫助2025-03-03
Android自定義view實(shí)現(xiàn)圖片選色器
這篇文章主要為大家詳細(xì)介紹了Android自定義view實(shí)現(xiàn)圖片選色器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06
讓Android中RadioGroup不顯示在輸入法上面的辦法
在Android開發(fā)中,發(fā)現(xiàn)一個(gè)問題,打開輸入法導(dǎo)致下面的radioGroup的位置發(fā)生了變化,被頂?shù)搅溯斎敕ǖ纳厦?,那么該如何解決呢?下面來看看。2016-08-08

