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

來源:互聯網
上載者:User

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硬體,我們可以通過設定該字串的值,來控制這三個硬體是否在切換飛航模式是進行切換狀態。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.