zoukankan      html  css  js  c++  java
  • RK Android7.1 设置 蓝牙 已断开连接

    连手机蓝牙 显示 蓝牙已断开连接

    一.

    1.1. /frameworks/base/packages/SettingsLib/res/values-zh-rCN/strings.xml

    <string name="bluetooth_disconnected" msgid="6557104142667339895">"已断开连接"</string>
    

    1.2.蓝牙配对 K:K-Rxxx_7.1_RK3399_FirmwareK_RXXX_RK3399_ANDROID7.1packagesappsSettingssrccomandroidsettingsluetoothBluetoothSettings.java

            @Override
            public void setListening(boolean listening) {
                BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
                if (defaultAdapter == null) return;
                if (listening) {
                    mEnabled = defaultAdapter.isEnabled();
                    mConnected =
                            defaultAdapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED;
    
    				Log.d("gatsby","state aaa -> "+ BluetoothAdapter.STATE_CONNECTED);
    				Log.d("gatsby","state bbb -> "+ defaultAdapter.getConnectionState());
    					
    						
                    mSummaryLoader.setSummary(this, getSummary());
                    mBluetoothManager.getEventManager().registerCallback(this);
                } else {
                    mBluetoothManager.getEventManager().unregisterCallback(this);
                }
            }
    
            private CharSequence getSummary() {
    			
    			Log.d("gatsby","!mEnabled -> "+ !mEnabled + " mConnected ->"+mConnected);
    
                return mContext.getString(!mEnabled ? R.string.bluetooth_disabled
                        : mConnected ? R.string.bluetooth_connected
                        : R.string.bluetooth_disconnected);
            }
    

    a. Log.d("gatsby","!mEnabled -> "+ !mEnabled + " mConnected ->"+mConnected);
    mEnabled ? R.string.bluetooth_disabled: mConnected ? R.string.bluetooth_connected: R.string.bluetooth_disconnected
    mEnabled ?"disabled" : mConnected ? "bluetooth_connected" : "bluetooth_disconnected";
    打开蓝牙开关 未连接蓝牙 !mEnabled -> false mConnected ->false

    b.mConnected = defaultAdapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED;

    defaultAdapter.getConnectionState() -> 0
    BluetoothAdapter.STATE_CONNECTED -> 2
    

    1.3.Android检查设备连接状态

    K:K-Rxxx_7.1_RK3399_FirmwareK_RXXX_RK3399_ANDROID7.1frameworksasecorejavaandroidluetoothBluetoothAdapter.java  

        /** The profile is in disconnected state */
        public static final int STATE_DISCONNECTED  = 0;	
    
    
        /**
         * Get the current connection state of the local Bluetooth adapter.
         * This can be used to check whether the local Bluetooth adapter is connected
         * to any profile of any other remote Bluetooth Device.
         *
         * <p> Use this function along with {@link #ACTION_CONNECTION_STATE_CHANGED}
         * intent to get the connection state of the adapter.
         *
         * @return One of {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTED},
         * {@link #STATE_CONNECTING} or {@link #STATE_DISCONNECTED}
         *
         * @hide
         */
        public int getConnectionState() {
            if (getState() != STATE_ON) return BluetoothAdapter.STATE_DISCONNECTED;
            try {
                mServiceLock.readLock().lock();
                if (mService != null) return mService.getAdapterConnectionState();
            } catch (RemoteException e) {
                Log.e(TAG, "getConnectionState:", e);
            } finally {
                mServiceLock.readLock().unlock();
            }
            return BluetoothAdapter.STATE_DISCONNECTED;
        }
    

    调用BluetoothAdapter中的getConnectionState()方法,直接检查是否存在连接状态的蓝牙设备存在 不能检测出手机发出的蓝牙 可以检测出蓝牙耳机  

        /** The profile is in disconnected state */
        public static final int STATE_DISCONNECTED  = 0;
        /** The profile is in connecting state */
        public static final int STATE_CONNECTING    = 1;
        /** The profile is in connected state */
        public static final int STATE_CONNECTED     = 2;
        /** The profile is in disconnecting state */
        public static final int STATE_DISCONNECTING = 3;
    

      

      

      

  • 相关阅读:
    项目实战从 0 到 1 学习之Flink (24)Flink将kafka的数据存到redis中
    LeetCode107. 二叉树的层次遍历 II
    LeetCode102. 二叉树的层序遍历
    LeetCode341. 扁平化嵌套列表迭代器
    【总结】二叉树的前中后序遍历(递归和非递归)
    LeetCode145. 二叉树的后序遍历
    LeetCode94. 二叉树的中序遍历
    LeetCode144. 二叉树的前序遍历
    LeetCode71. 简化路径
    LeetCode150. 逆波兰表达式求值
  • 原文地址:https://www.cnblogs.com/crushgirl/p/14846534.html
Copyright © 2011-2022 走看看