Android Bluetooth development of the pit

read failed return -1

Bluetooth connection most critical step connect the most problematic. And there are several pits,

0Android studio simulator will be reported and therefore no Bluetooth adapter is absent, replaced by a real machine to debug

1connect must be placed in a separate thread

2 There are several ways to obtain socket, which is why a problem. Or may first select insecureRfcomm Rfcomm according sdk version, try connect reused if it fails to connect reflection. Reflection band is also connected to a UUID and without UUID.

When I finally realized that the code inside constantly try connect. One method would not replaced one kind. Finally, using the reflection without the UUID 100% complete connection.

3 If the results are wrong, not connected, please check when debugging device socket is null

4 turning on the device Bluetooth pairing point manually on the phone. After pairing is complete connect in the app.

Life-cycle variables 5 Note the use of possible bug.

Guess you like

Origin www.cnblogs.com/sleeploke/p/12036826.html