Error Error - 1 year ago 440
Android Question

Register broadcast receiver dynamically does not work - BluetoothDevice.ACTION_FOUND


class to track Runtime show that
methode does not called,why ?

Register broadcast receiver dynamically

private void discoverDevices () {

mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
Bluetooth b = new Bluetooth(device.getName(),device.getAddress());
Log.e("MOHAB","create intentFilter");
// Register the BroadcastReceiver
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy


Answer Source

What you missed is that you need to start a device recovery

First, get the bluetooth adapter

BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

After that, you start the discovery by calling


You should read the details here as well, e.g. about cancelDiscovery()

P.S. Also, it is suggested to use context.getSystemService(Context.BLUETOOTH_SERVICE) to get the BluetoothAdapter on API 18+, according to official doc.

To get a BluetoothAdapter representing the local Bluetooth adapter, when running on JELLY_BEAN_MR1 and below, call the static getDefaultAdapter() method; when running on JELLY_BEAN_MR2 and higher, retrieve it through getSystemService(Class) with BLUETOOTH_SERVICE.

Edit: Be reminded that you need BLUETOOTH_ADMIN permission to startDiscovery()