Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am using SGSIII mini as well for development. The following code works well for me: </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); tmp = device.createInsecureRfcommSocketToServiceRecord(MY_UUID); } catch (IOException e) { Log.e(LOG_TAG, "create() failed", e); } mmSocket = tmp; Main.myBluetoothSocket = mmSocket; Main.myBluetoothDevice = mmDevice; } @Override public void run() { Log.i(LOG_TAG, "BEGIN mConnectThread"); setName("ConnectThread"); // Always cancel discovery because it will slow down a connection mAdapter.cancelDiscovery(); // Send a failure message back to the Activity Message msg = mHandler.obtainMessage(MESSAGE_TOAST); Log.e(LOG_TAG, "Attempting connection to " + mmSocket.getRemoteDevice().getName()); String ss = "Attempting connection to " + mmSocket.getRemoteDevice().getName(); Bundle bundle = new Bundle(); bundle.putString(TOAST, ss); msg.setData(bundle); mHandler.sendMessage(msg); // 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(LOG_TAG, "*+*+*+* Connection Failed"); connectionFailed(); // Close the socket try { mmSocket.close(); } catch (IOException e2) { Log.e(LOG_TAG, "unable to close() socket during connection failure", e2); } // Start the service over to restart listening mode BluetoothCommandService.this.start(); return; } // Reset the ConnectThread because we're done synchronized (BluetoothCommandService.this) { mConnectThread = null; } // Start the connected thread connected(mmSocket, mmDevice); } public void cancel() { try { mmSocket.close(); } catch (IOException e) { Log.e(LOG_TAG, "close() of connect socket failed", e); } } } </code></pre>
    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.
    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