如何使用BLE 5 2M PHY提高数据传输速度?

时间:2020-06-16 07:50:15

标签: android bluetooth-lowenergy

现在,我正在为支持蓝牙5的手机开发一个android应用,并与BLE 5设备通信。我正在尝试使用以下代码来最大化蓝牙通信,但失败了。是否有使用BLE 5的2M PHY来最大化数据传输速度的示例代码或示例。

  public void setPhy2M() {
     final BluetoothGatt gatt = mBluetoothGatt;
     if (gatt == null) return

     int retry = 5;
     boolean status = false;
     while (!status && retry > 0) {
        SystemClock.sleep(150);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            status = gatt.requestMtu(mtu);
        }
        retry--;
     }
     SystemClock.sleep(100);
     if (BluetoothAdapter.getDefaultAdapter().isLe2MPhySupported() 
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
         gatt.setPreferredPhy(BluetoothDevice.PHY_LE_2M_MASK, BluetoothDevice.PHY_LE_2M_MASK, BluetoothDevice.PHY_OPTION_NO_PREFERRED); 
     }
   }

0 个答案:

没有答案