android在開啟飛航模式的情況下,禁止開啟藍芽

來源:互聯網
上載者:User

標籤:android   io   ar   os   sp   for   java   on   檔案   



(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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: 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.