首页 > 代码库 > android在开启飞行模式的情况下,禁止打开蓝牙
android在开启飞行模式的情况下,禁止打开蓝牙
(1)将alps/framework/base/packages/settingsprovider/res/values/defaults.xml里
面airplane_mode_toggleable_radios标签中的“bluetooth”去掉。
(2)在packages/apps/settings/src/android/settings/bluetoothangel/BluetoothEnabler.java这支文件里进行如下修改:
1.import 如下两个包:
import android.database.ContentObserver;
import com.android.settings.AirplaneModeEnabler;
import android.os.Handler;
2. 在resume()方法的末尾添加如下语句:
//add
mContext.getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.AIRPLANE_MODE_ON), true,
mAirplaneModeObserver);
mSwitch.setEnabled(!shouldDisableBT());
//add end
3.在pause()方法里面添加如下语句:
//add
mContext.getContentResolver().unregisterContentObserver(mAirplaneModeObserver);
//add end
4. 在setSwitch()方法里注释掉如下语句:
//mSwitch.setEnabled(isOn || isOff);
添加如下语句:
mSwitch.setEnabled(!shouldDisableBT()); //add
5. 将handleStateChanged()方法里面的BluetoothAdapter.STATE_ON,BluetoothAdapter.OFF和default
这三个case里的mSwitch.setEnabled(true);修改为:
mSwitch.setEnabled(!shouldDisableBT()); // add
6.在BluetoothEnabler这个class添加如下方法和成员变量:
//add
private boolean shouldDisableBT(){
String toggleable = Settings.System.getString(mContext.getContentResolver(),
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
if(toggleable == null || !toggleable.contains(Settings.System.RADIO_BLUETOOTH)){
return AirplaneModeEnabler.isAirplaneModeOn(mContext);
}
return false;
}
// add
private ContentObserver mAirplaneModeObserver = new ContentObserver(new
Handler()) {
@Override
public void onChange(boolean selfChange) {
onAirplaneModeChanged();
}
};
// add
private void onAirplaneModeChanged() {
mSwitch.setEnabled(!AirplaneModeEnabler.isAirplaneModeOn(mContext));
}
(3)ALPS.JB.MP\alps\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\tool
bar\connectionSwitchPannel.java
在private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
里面的onReceive()函数里的
else if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
这个判断分支内最后添加:
//add for airplan -bt toggle state
mBluetoothStateTracker.setAirlineMode(enabled);
mBluetoothIcon.getConfigView().setEnabled(mBluetoothStateTracker.isClickable());
//add end
BluetoothStateTracker 类中添加如下代码
class BluetoothStateTracker extends StateTracker {
//add
private
boolean mIsAirlineMode = false;
public void setAirlineMode(boolean
enable) {
if (DBG) {
Xlog.i(TAG, "Bluetooth setAirlineMode
called, enabled is: " + enable);
}
mIsAirlineMode = enable;
}
public boolean isClickable() {
Xlog.i(TAG, "BT mIsAirlineMode
is " + mIsAirlineMode + ", mIsUserSwitching is " + mIsUserSwitching);
return
!mIsAirlineMode && super.isClickable();
}
//add end
(4)\alps\packages\apps\Settings\src\com\android\settings\widget\SettingsAppWidgetProvider.java
//add
import com.android.settings.AirplaneModeEnabler;
//add end
else if ((FeatureOption.MTK_BT_SUPPORT) && (buttonId == BUTTON_BLUETOOTH)) {
//sBluetoothState.toggleState(context);
//add
if(!AirplaneModeEnabler.isAirplaneModeOn(context)) {
sBluetoothState.toggleState(context);
}
//add end
}
android在开启飞行模式的情况下,禁止打开蓝牙
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。