title: Programmatically connecting to a Bluetooth enabled barcode scanner in Android
body: <p>I am working to create an Android App that connects to a bluetooth barcode scanner. I've been looking for code examples of how to do this but I can not find any dealing with connecting to a device. I see lots for connecting peer-to-peer with android devices but that doesn't seem to cover android to device.</p>
  
  <p>This is the code I have so far.  It fails on the call to connect with a Connection refused.</p>
  
  <pre><code>UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  socket = mDevice.createRfcommSocketToServiceRecord(uuid);
  socket.connect();
  
  06-11 15:29:10.113: W/System.err(20018): java.io.IOException: Connection refused
  06-11 15:29:10.133: W/System.err(20018):    at  android.bluetooth.BluetoothSocket.connectNative(Native Method)
  06-11 15:29:10.133: W/System.err(20018):    at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:212)
  </code></pre>
  
  <p>The device is paired with the android phone and I retrieve it from the phone using this.</p>
  
  <pre><code>Set&lt;BluetoothDevice&gt; pairedDevices = btAdapter.getBondedDevices();
  </code></pre>