Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Bluetooth Connection Secure Insecure
    text
    copied!<p>I have been playing around with the bluetooth API for Android 2.2 (API level 8, HTC Desire) and had an app connecting to an embedded Bluetooth device using:</p> <pre><code>device.createRfcommSocketToServiceRecord(DEV_UUID); </code></pre> <p>This generated a pairing request as expected, however to streamline the connection process I wanted to avoid the user interaction when pairing so moved to API level 10 (HTC Desire with CyanogenMod 7) so I could use:</p> <pre><code> device.createInsecureRfcommSocketToServiceRecord(DEV_UUID); </code></pre> <p>When testing this also works as expected (connecting without prompting the user to pair), however when I try to create the secure RfcommSocket under API level 10 as before with 2.2 I get a connection refused exception...</p> <pre><code> java.io.IOException: Connection refused at android.bluetooth.BluetoothSocket.connectNative(Native Method) at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:204) </code></pre> <p>As far as I can tell this should still work in the same way, prompting the user to pair?</p> <p>EDIT: </p> <p>Just tried again using the following code and the outcome is the same (working for insecure but not for secure), I will try and get my hands on a stock 2.3 device to test on. </p> <pre><code> try { Method m = dev.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class } ); BluetoothSocket bs = (BluetoothSocket)m.invoke(dev, devUUID); Log.d("TEST", "Method Invoked"); bs.connect(); Log.d("TEST", "Connected to socket"); bs.close(); Log.d("TEST", "Closed Socket"); } </code></pre>
 

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