How to scan for available bluetooth devices in range in android?

后端 未结 3 1613
南旧
南旧 2020-12-08 08:05

I need to get a list of available bluetooth devices in the area using google android 2.1.

Thing is, i don\'t just need a list of those devices, i need some unique id

3条回答
  •  情歌与酒
    2020-12-08 08:44

    Check out code below :

    Starting search

    mBluetoothAdapter.startDiscovery(); 
    mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
    
        //Finding devices                 
        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
           mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
      }
    };
    
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
    registerReceiver(mReceiver, filter);
    

提交回复
热议问题