国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android 如何判斷當前是否為飛行模式

2020-04-11 12:41:30
字體:
來源:轉載
供稿:網友
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硬件,我們可以通過設置該字符串的值,來控制這三個硬件是否在切換飛行模式是進行切換狀態。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 杭州市| 鄄城县| 湛江市| 满城县| 玛纳斯县| 海门市| 疏附县| 清苑县| 清水县| 冷水江市| 汉寿县| 鹿泉市| 凭祥市| 韶山市| 广德县| 镇沅| 贡觉县| 闽清县| 江陵县| 温泉县| 老河口市| 剑河县| 谢通门县| 汝阳县| 长垣县| 泸州市| 泾源县| 建始县| 湘潭市| 文成县| 盖州市| 鸡西市| 德安县| 游戏| 勐海县| 永修县| 景德镇市| 郑州市| 敦化市| 鄂州市| 枣强县|