蓝牙开发

android蓝牙通讯 java.io.IOException: Service disco...

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 04:45:06
研究android蓝牙连接时,在网上找了个例子,作为客户端在调用connect函数时失败。经查资料 将 socket = device.createRfcommSocketToServiceRecord(UUID.fromString("a60f35f0-b93a-11de-8a39-08002009c666")); 改为 Method m; try { m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); try { socket = (BluetoothSocket) m.invoke(device, 1); _bluetooth.cancelDiscovery(); try { socket.connect(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto