Essential Android Bluetooth LE API edit forum

Find nearby bluetooth devices

Declare a BluetoothAdapter first.

BluetoothAdapter mBluetoothAdapter;

Now create a BroadcastReceiver for ACTION_FOUND

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

    //Device found                
    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 list
        mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
    }
  }
};

Register the BroadcastReceiver

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);

Then start discovering the nearby bluetooth devices by calling startDiscovery

mBluetoothAdapter.startDiscovery();

Don’t forget to unregister the BroadcastReceiver inside onDestroy

unregisterReceiver(mReceiver);

Table Of Contents
39 ACRA
64 Menu
67 Bluetooth LE API
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close