Note that there are some explanatory texts on larger screens.

plurals
  1. POService discovery failed with app based on android bluetooth chat sample
    primarykey
    data
    text
    <p>I am writing an Bluetooth game with blue tooth part based on android Bluetooth chat sample. And I have two phones to test. Here is the problem, when I connect one phone to the other, it sometimes shows the "Unable to connect device" bundle, but when I run the Bluetooth chat sample, it never shows this, so I think it is not the problem of device. Is there anyone who has studied the Bluetooth chat sample and has the same problem that would give me some help?</p> <p>I try to print the exception, it is like "java.io.IOException: Service discovery failed". And here is the code that cause the exception.</p> <pre><code>private class ConnectThread extends Thread { private final BluetoothSocket mmSocket; private final BluetoothDevice mmDevice; public ConnectThread(BluetoothDevice device) { mmDevice = device; BluetoothSocket tmp = null; // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { tmp = device.createRfcommSocketToServiceRecord(MY_UUID); } catch (IOException e) { Log.e(TAG, "create() failed", e); } mmSocket = tmp; } public void run() { Log.i(TAG, "BEGIN mConnectThread"); setName("ConnectThread"); // Always cancel discovery because it will slow down a connection 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 mmSocket.connect(); } catch (IOException e) { Log.e("error", e.toString()); connectionFailed(); // Close the socket try { mmSocket.close(); } catch (IOException e2) { Log.e(TAG, "unable to close() socket during connection failure", e2); } // Start the service over to restart listening mode BluetoothChatService.this.start(); return; } // Reset the ConnectThread because we're done synchronized (BluetoothChatService.this) { mConnectThread = null; } // Start the connected thread connected(mmSocket, mmDevice); } public void cancel() { try { mmSocket.close(); } catch (IOException e) { Log.e(TAG, "close() of connect socket failed", e); } } } </code></pre> <p>The exact position is<br> <code>mmSocket.connect();</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload