X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FBluetoothChatService.java;h=03edeb93df0378dda8f2e05b652879b0007c42aa;hb=322a8560ff2b7f6847b11d14d6d7d93992ecdf95;hp=93cb75de8b6e9092899f61e14b54e904b612851d;hpb=ec48b388fc6c9b15d0d294296c212fe06ab8c6ed;p=fw%2Faltos diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/BluetoothChatService.java b/altosdroid/src/org/altusmetrum/AltosDroid/BluetoothChatService.java index 93cb75de..03edeb93 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/BluetoothChatService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/BluetoothChatService.java @@ -236,15 +236,17 @@ public class BluetoothChatService { // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { + Log.i(TAG, "Connect starting"); if (secure) { Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); - tmp = (BluetoothSocket) m.invoke(device, 2); + tmp = (BluetoothSocket) m.invoke(device, 1); // tmp = device.createRfcommSocket(1); } else { Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class}); - tmp = (BluetoothSocket) m.invoke(device, 2); + tmp = (BluetoothSocket) m.invoke(device, 1); // tmp = device.createInsecureRfcommSocket(1); } + Log.i(TAG, "Connect succeeded"); } catch (Exception e) { Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e); e.printStackTrace(); @@ -253,19 +255,21 @@ public class BluetoothChatService { } public void run() { - Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType); + Log.i(TAG, "BEGIN ya y a mConnectThread SocketType:" + mSocketType); setName("ConnectThread" + mSocketType); // Always cancel discovery because it will slow down a connection - mAdapter.cancelDiscovery(); +// mAdapter.cancelDiscovery(); // Make a connection to the BluetoothSocket try { // This is a blocking call and will only return on a // successful connection or an exception + Log.i(TAG, "CONNECT SocketType:" + mSocketType); mmSocket.connect(); } catch (IOException e) { // Close the socket + Log.e(TAG, "Connect failed", e); try { mmSocket.close(); } catch (IOException e2) { @@ -332,9 +336,12 @@ public class BluetoothChatService { // Read from the InputStream bytes = mmInStream.read(buffer); - // Send the obtained bytes to the UI Activity - mHandler.obtainMessage(AltosDroid.MESSAGE_READ, bytes, -1, buffer) + if (bytes > 0) { + Log.i(TAG, "Recv: " + new String(buffer, 0, bytes)); + // Send the obtained bytes to the UI Activity + mHandler.obtainMessage(AltosDroid.MESSAGE_READ, bytes, -1, buffer) .sendToTarget(); + } } catch (IOException e) { Log.e(TAG, "disconnected", e); connectionLost();