Android - Bluetooth discovery doesn't find any device
<p>I'm currently working on a little app to get started with the services that the Bluetooth Android API can provide. </p>

<p><strong>Edit -> Answer:</strong></p>

<p>It seems that the issue was due to the specific Nexus 5 devices. Seems like their bluetooth receiver doesn't work well. Solution below should work for other devices</p>

<p><strong>Remark:</strong></p>

<ol>
<li><p>I’ve read the documentation here: <a href="http://developer.android.com/guide/topics/connectivity/bluetooth.html">http://developer.android.com/guide/topics/connectivity/bluetooth.html</a>
as well as the following source code of this tutorial <a href="http://www.londatiga.net/it/programming/android/how-to-programmatically-scan-or-discover-android-bluetooth-device/">http://www.londatiga.net/it/programming/android/how-to-programmatically-scan-or-discover-android-bluetooth-device/</a> located on github under /lorensiuswlt/AndroBluetooth</p></li>
<li><p>I’ve finished almost all the features that interested me (such as check for adapter existence, enable/disable the blueooth, querying paired divices, set the adapter discoverable).</p></li>
</ol>

<p><strong>Issue:</strong></p>

<p>Actually <strong>no device is found</strong> when i launch the .onDiscovery() method, even though devices are found from Settings/Bluetooth on my Nexus 5.</p>

<p>Here is how I handle it:</p>

<pre><code>public class MainActivity extends AppCompatActivity {
private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

...

protected void onCreate(Bundle savedInstanceState) {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(mReceiver, filter); 
}
</code></pre>

<p>The <strong>filter is working well</strong> as far as i could try, i.e ACTION_STATE_CHANGED (on bluetooth enabling) and the two ACTION_DISCOVERY_***.</p>

<p>The following method is then successfuly called:</p>

<pre><code>public void onDiscovery(View view)
{
    mBluetoothAdapter.startDiscovery();
}
</code></pre>

<p>And then i have my bluetooth receiver:</p>

<pre><code>private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
            final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);

            if (state == BluetoothAdapter.STATE_ON) {
                showToast("ACTION_STATE_CHANGED: STATE_ON");
            }
        }

        else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
            mDeviceList = new ArrayList&lt;&gt;();
            showToast("ACTION_DISCOVERY_STARTED");
            mProgressDlg.show();
        }

        else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action) &amp;&amp; !bluetoothSwitchedOFF) {
            mProgressDlg.dismiss();
            showToast("ACTION_DISCOVERY_FINISHED");

            Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class);

            newIntent.putParcelableArrayListExtra("device.list", mDeviceList);

            startActivity(newIntent);
        }

        else if (BluetoothDevice.ACTION_FOUND.equals(action)) {// When discovery finds a device
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            mDeviceList.add(device);
            showToast("Device found = " + device.getName());
        }
    }
};
</code></pre>

<p>I don't have any issue coming out the logcat and didn't notice any trouble during the test I did. The only problem is that <strong>no device is discovered</strong> at the end of the scan, when many discoverable ones are available arround. </p>

<p>I tried to not put too much code in order to not flood the topic. Ask me if you need more.</p>

<p>Thanks for reading me, and thanks in advance for you answers.</p>