android藍牙通信 java.io.IOException: Service disco...

研究android藍牙鏈接時,在網上找了個例子,做爲客戶端在調用connect函數時失敗。經查資料
java

android

 

socket = device.createRfcommSocketToServiceRecord(UUID.fromString("a60f35f0-b93a-11de-8a39-08002009c666"));

改成socket

 

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-generated catch block
 e.printStackTrace();
 } catch (InvocationTargetException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 } catch (SecurityException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (NoSuchMethodException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }

就能夠鏈接。函數

緣由還沒查出來。作個標記。
  測試

有人說用00001101-0000-1000-8000-00805F9B34FB這個UUID就能夠。code

但我測試使用這個UUID一樣會出現:get

10-26 08:04:20.196: ERROR/ClientSocketActivity(2147): java.io.IOException: Service discovery failed
 it

相關文章
相關標籤/搜索