title: Connect to Bluetooth programmatically
body: <p>I'm trying to connect programmatically my device to for example on my Headsets... I had <code>KitKat</code> version and all worked perfect (<code>Bluetooth</code> always was connecting without problems autommatically) but since I've updated to <code>Lolipop</code> it doesn't. I'd like to know if there is any way to connect any paired device of my <code>Android phone</code> to <code>Bluetooth</code> when it turns on.</p>
  
  <p>Since now I've this code (gets the Device name and Device Address) because I thought with it I could connect doing something like <code>device.connect(MAC-Address);</code> but it didn't work...</p>
  
  <pre><code>    BluetoothAdapter bluetoothAdapter
      = BluetoothAdapter.getDefaultAdapter();
  Set &lt; BluetoothDevice &gt; pairedDevices = bluetoothAdapter.getBondedDevices();
  if (pairedDevices.size() &gt; 0) {
      for (BluetoothDevice device: pairedDevices) {
          mDeviceName.add(device.getName());
          mDeviceMAC.add(device.getAddress());
  
      }
  }
  bluetoothClass.setDeviceName(mDeviceName);
  bluetoothClass.setDeviceMac(mDeviceMAC);
  </code></pre>
  
  <h2><strong>Question</strong></h2>
  
  <p>On my MotoG (KitKat) if I turn my <code>Bluetooth</code> it connects autommatically to device (if it's near and paired ofc...) but on my LG G3 I must go to Configuration/Bluetooth/Paired devices/ and there tap the device to connect... and I want to avoid this... should be possible?</p>
  
  <hr>
  
  <p>I would like to know if there is any possibility to connect to specific Bluetooth just adding the <code>Device name</code> or <code>Device MAC</code>... More or less like <code>Android</code> does when I click on my device to connect it connects autommatically... I just want to get that CLICK event.
  I know that <code>Android</code> should connect autommatically to a paired device but there's any exceptions that doesn not ... the only way to pair it it's doing the click... that's why I'm wondering if it's there a way to do it...
  I've read and tested <a href="https://stackoverflow.com/a/18397935/4385913">kcoppock answer</a> but it still don't work ..</p>
  
  <p>Any suggestion? </p>
  
  <h2>EDIT</h2>
  
  <p>The main thing that I wanted to do is to connect my <code>Bluetooth</code> autommatically but since I've read on <a href="https://stackoverflow.com/a/31840258/4385913">Hey you</a> answer... I figured it out and I know it's an <code>Android</code> bug, so the thing that I would like to do is select the <code>paired devices</code> and then click on the device that I want to connect <strong>(Without doing any <code>Intent</code>)</strong> and connect it, instead to go <code>Configuration/Bluetooth/...</code>.
  Btw I've read any answers on <code>StackOverflow</code> and I found something with <code>Sockets</code> are they used to connect <code>Bluetooth</code>?Could be it a solution?</p>