title: BLE with Android 5.0 : How to get a device to act as Central AND Server?
body: <p>I'm using two Android 5.0 devices to communicate through Bluetooth Low Energy and I wan't :</p>
  
  <ul>
  <li><p><strong>Device 1</strong> to act as <strong>Central and Server</strong>. </p></li>
  <li><p><strong>Device 2</strong> to act as <strong>Peripheral and Client</strong>. </p></li>
  </ul>
  
  <hr>
  
  <p>This is the behavior I'd like to achieve : </p>
  
  <p>1) Device 2 starts advertising (peripheral role). </p>
  
  <p>2) Device 1 starts scanning (central role), and gets the advertising device (BluetoothDevice object) through the ScanCallback's onScanResult method. </p>
  
  <p>3) I now want the advertising device (Device 2) to be notified that it has been scanned and be able to get the BluetoothDevice associated with Device 1. </p>
  
  <p>4) Device 1 has an instance of BluetoothGattServer. Device 2 would now call connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback) on Device 1 to get an instance of BluetoothGatt. </p>
  
  <p>5) In the end, Device 1 is Server and Device 2 is Client. </p>
  
  <hr>
  
  <p>So far I've found that in step 2, once Device 1 holds the BluetoothDevice for Device 2, it can only connect as client like in step 4 using connectGatt. </p>
  
  <p>I might be able to use the <em>BluetoothGattServer</em> defined in Device 1, and call : <em>gattServer.connect(BluetoothDevice device, boolean autoConnect)</em> with <em>device</em> being Device 2. </p>
  
  <p>But <strong>how will Device 2 be notified it's been connected to ?</strong> </p>
  
  <p>And <strong>how will I get an instance of <em>BluetoothGatt</em> in Device 2 if I can't call  <em>connectGatt(Context, boolean, BluetoothGattCallback)</em> on a <em>BluetoothDevice</em>?</strong> </p>
  
  <p>Thank you in advance for your help !</p>
  
  <p>Some documentation :</p>
  
  <p><a href="http://developer.android.com/reference/android/bluetooth/BluetoothGattServer.html" rel="noreferrer">BluetoothGattServer</a></p>
  
  <p><a href="http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html" rel="noreferrer">BluetoothDevice</a></p>