title: Unable to establish connection with the BluetoothHidDevice profile to a Windows 10 PC
body: <p>I'm attempting to write an app that connects to another device via bluetooth, identify itself as a keyboard via the new <a href="https://developer.android.com/reference/android/bluetooth/BluetoothHidDevice" rel="nofollow noreferrer"><code>BluetoothHidDevice</code></a> and then send text and/or single characters to the target device as keyboard input.</p>
  
  <p>So far I got everything to work except establishing the bluetooth connection from my Huawei P10 to a Windows 10 laptop. It seems to work fine when connecting to another Android device when I tested it with a Galaxy S8+ on the receiving end, when I tried to establish a connection the P10 got correctly detected as a physical keyboard and I could send keyboard inputs to the S8+</p>
  
  <p>I also tried it with two different laptops, one with a built-in bluetooth adapter and another with an external usb adapter, in both cases I was unable to establish a connection.</p>
  
  <p>My code is mostly based on <a href="https://github.com/ginkage/wearmouse" rel="nofollow noreferrer">https://github.com/ginkage/wearmouse</a> by google which I found thanks to another <a href="https://stackoverflow.com/a/57137850">question</a> while I was looking for solutions to my own issue.</p>
  
  <p>The issue is that there is no connection established after calling <a href="https://developer.android.com/reference/android/bluetooth/BluetoothHidDevice#connect(android.bluetooth.BluetoothDevice)" rel="nofollow noreferrer"><code>BluetoothHidDevice#connect</code></a> which returns <code>true</code> as expected but then seemingly just times out.</p>
  
  <p>When observing the log I just see the state switching between 1 (connecting) and 0 (disconnected):</p>
  
  <pre><code>D/BluetoothHidDevCallback: onConnectionStateChanged: device=[redacted MAC] state=1
  D/BluetoothHidDevCallback: onConnectionStateChanged: device=[redacted MAC] state=0
  ...
  </code></pre>
  
  <p>I set up an android studio project where you just need to change <code>TARGET_DEVICE_NAME</code> inside of <code>MainActivity.java</code> to your target devices name and it should run out of the box (requires Android 9 Pie): <a href="https://github.com/domi1294/BluetoothHidDemo" rel="nofollow noreferrer">https://github.com/domi1294/BluetoothHidDemo</a></p>
  
  <p>Your devices need to be paired beforehand since it will check your paired devices for <code>TARGET_DEVICE_NAME</code> and attempt to connect to it when you press the button. If the connection was successful the button will instead send the string <code>"TestMessage"</code> to the target device.</p>
  
  <p>If you run the app yourself and track <code>BluetoothHidDevCallback</code> in Logcat you should see it try to connect (state=1), disconnect (state=0) and repeat. It should change to state 2 which stands for connected and is what I expect to happen like it did when I tried the P10 --> S8+ connection.</p>
  
  <p>Feel free to try connecting to a macOS device if you don't own a Windows pc, as I would like to know whether this is a Windows only problem or not.</p>