Cómo obtener dispositivos conectados a bluetooth mediante BluetoothHeadset API

Quiero obtener una lista de dispositivos conectados a bluetooth … no sólo dispositivos emparejados.

Encontré BluetoothHeadset API en el nivel 11 de la API que proporciona el método getConnectedDevices() para obtener la lista de dispositivos Bluetooth conectados.

¿Cómo obtener la lista de dispositivos conectados a bluetooth usando esta API?

    Finalmente obtuvo la solución …. A continuación se muestra el código correcto para obtener dispositivos conectados de audio BluetoothHeadset mediante BluetoothHeadset API.

     BluetoothHeadset mBluetoothHeadset; // Get the default adapter BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // Establish connection to the proxy. mBluetoothAdapter.getProfileProxy(context, mProfileListener, BluetoothProfile.HEADSET); // Define Service Listener of BluetoothProfile private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() { public void onServiceConnected(int profile, BluetoothProfile proxy) { if (profile == BluetoothProfile.HEADSET) { mBluetoothHeadset = (BluetoothHeadset) proxy; } } public void onServiceDisconnected(int profile) { if (profile == BluetoothProfile.HEADSET) { mBluetoothHeadset = null; } } }; //call functions on mBluetoothHeadset to check if Bluetooth SCO audio is connected. List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices(); for ( final BluetoothDevice dev : devices ) { return mBluetoothHeadset.isAudioConnected(dev); } // finally Close proxy connection after use. mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset); 

    Primero debes definir el permiso en Androindmanifest.xml

     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH" /> 

    Búsqueda de dispositivos conectados Actividad,

     private static BluetoothAdapter mBtAdapter; private final static int REQUEST_ENABLE_BT = 1; // Register for broadcasts when a device is discovered IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); this.registerReceiver(mReceiver, filter); // Register for broadcasts when discovery has finished filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); this.registerReceiver(mReceiver, filter); filter = new IntentFilter( BluetoothAdapter.ACTION_DISCOVERY_STARTED ); this.registerReceiver( mReceiver, filter ); 

    Clase BroadCastReceiver

     private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { try { 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); } } catch ( Exception e ) { logger.info( DateFormat.format( ConstantCodes.dateFormat ,new java.util.Date()).toString(),"Broadcast Error : " + e.toString(), ConstantCodes.SEARCH_ACTIVITY ); System.out.println ( "Broadcast Error : " + e.toString() ); } } }; 
    FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.