Bluetooth -> service discovery failed

前端 未结 6 2019
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 21:55

I\'m writing an application that is able to communicate with my PC. I have used the Bluetooth functionalities of the SDK 2.1.

I can find devices, get their MAC address,

6条回答
  •  失恋的感觉
    2021-01-31 22:37

    I found a way to be sure that the UUID is found on the device. On the client side, before device.createRfcommSocketToServiceRecord(uuid); add:

    Process process = Runtime.getRuntime().exec("su -c 'sdptool records " + device.getAddress() + "'");
    process.waitFor();
    

    The process is frozen during 20-30 seconds, because Android is fetching services. But after, if the server is in discovery mode (if the server is an Android phone), the connection succeeds every time!

提交回复
热议问题