RK Android7.1 设置->蓝牙->已断开连接 Android6.0 直接弹窗

 

一. Android7.1 连手机蓝牙 显示 蓝牙已断开连接

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

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

1.2.蓝牙配对 K:\ZK-Rxxx_7.1_RK3399_Firmware\ZK_RXXX_RK3399_ANDROID7.1\packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothSettings.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:\ZK-Rxxx_7.1_RK3399_Firmware\ZK_RXXX_RK3399_ANDROID7.1\frameworks\base\core\java\android\bluetooth\BluetoothAdapter.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;

 二.Android6.0  蓝牙直接弹窗  

2.1.packages\apps\Bluetooth\src\com\android\bluetooth\btservice\AdapterProperties.java

     void updateFeatureSupport(byte[] val) {  

--- a/packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterProperties.java
+++ b/packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterProperties.java
@@ -612,11 +612,11 @@ class AdapterProperties {
                        adapterPropertyChangedCallback received before
                        onBluetoothReady */
                     if (mDiscoverableTimeout != 0)
-                      setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE);
+                      setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
                     else /* if timeout == never (0) at startup */
                       setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
                     /* though not always required, this keeps NV up-to date on first-boot after flash */
-                    setDiscoverableTimeout(mDiscoverableTimeout);
+                    setDiscoverableTimeout(0/*mDiscoverableTimeout*/);
             }
         }
     }

2.2.packages\apps\Bluetooth\src\com\android\bluetooth\opp\BluetoothOppNotification.java

  private void updateIncomingFileConfirmNotification() {

--- a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -526,6 +526,15 @@ class BluetoothOppNotification {
             n.deleteIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
 
             mNotificationMgr.notify(id, n);
+			
+			Uri uri = intent.getData();
+            Intent in = new Intent(mContext, BluetoothOppIncomingFileConfirmActivity.class);
+            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            in.setDataAndNormalize(uri);
+            mContext.startActivity(in);
+
+            NotificationManager notGatsby = (NotificationManager)mContext
+                    .getSystemService(Context.NOTIFICATION_SERVICE);
         }
         cursor.close();
     }

  

  

  

posted @ 2021-06-03 19:15  CrushGirl  阅读(679)  评论(0编辑  收藏  举报