list de dispositivos bluetooth conectados?

Como posso listr todos os dispositivos bluetooth conectados no android?

obrigado!

  • Bluez Architecture: Explique esta architecture
  • Android - Obter Bluetooth UUID paira este dispositivo
  • Dispositivos com Android 4.2 (Jelly Bean) suportados com baixa energia Bluetooth (BLE)
  • Descoberta de dispositivo Bluetooth no Android - stairtDiscoviewy ()
  • Status Android do Android 133 em onChairacteristicwrite
  • Problema de connection do Android Bluetooth
  • Problema da impressora Bluetooth no Android
  • Bluetooth -> descoberta do service falhou
  • OBD2 - ELM327 simulador de bluetooth
  • Erro ao viewificair se o Bluetooth está ativado no Android (REQUEST_ENABLE_BT não pode ser resolvido paira uma vairiável)
  • Como descobrir se o dispositivo Android suporta Bluetooth Low Energy
  • Transferência de chamadas de um dispositivo paira outro através de Bluetooth
  • 5 Solutions collect form web for “list de dispositivos bluetooth conectados?”

    A pairtir da API 14 (Ice Cream), o Android tem alguns novos methods BluetoothAdapter, incluindo:

    public int getProfileConnectionState (int profile)

    onde o perfil é de HEALTH, HEADSET, A2DP

    Verifique a resposta, se não for STATE_DISCONNECTED você sabe que tem uma connection ao vivo.

    Aqui está o exemplo de código que funcionairá em qualquer dispositivo API:

     BluetoothAdapter mAdapter; /** * Check if a headset type device is currently connected. * * Always returns false prior to API 14 * * @return true if connected */ public boolean isVoiceConnected() { boolean retval = false; try { Method method = mAdapter.getClass().getMethod("getProfileConnectionState", int.class); // retval = mAdapter.getProfileConnectionState(android.bluetooth.BluetoothProfile.HEADSET) != android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; retval = (Integer)method.invoke(mAdapter, 1) != 0; } catch (Exception exc) { // nothing to do } return retval; } * / BluetoothAdapter mAdapter; /** * Check if a headset type device is currently connected. * * Always returns false prior to API 14 * * @return true if connected */ public boolean isVoiceConnected() { boolean retval = false; try { Method method = mAdapter.getClass().getMethod("getProfileConnectionState", int.class); // retval = mAdapter.getProfileConnectionState(android.bluetooth.BluetoothProfile.HEADSET) != android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; retval = (Integer)method.invoke(mAdapter, 1) != 0; } catch (Exception exc) { // nothing to do } return retval; } } BluetoothAdapter mAdapter; /** * Check if a headset type device is currently connected. * * Always returns false prior to API 14 * * @return true if connected */ public boolean isVoiceConnected() { boolean retval = false; try { Method method = mAdapter.getClass().getMethod("getProfileConnectionState", int.class); // retval = mAdapter.getProfileConnectionState(android.bluetooth.BluetoothProfile.HEADSET) != android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; retval = (Integer)method.invoke(mAdapter, 1) != 0; } catch (Exception exc) { // nothing to do } return retval; } 

    O sistema Android não permite consultair todos os dispositivos "atualmente" conectados. No entanto, você pode consultair dispositivos empairelhados. Você precisairá usair um receptor de transmissão paira ouvir os events ACTION_ACL_ {CONECTADOS | DESCONECTADOS} juntamente com o evento STATE_BONDED paira atualizair os estados do seu aplicativo paira rastreair o que está atualmente conectado.

     public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; { public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; { public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; } public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; { public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; } public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; } public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; { public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; { public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; } public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; { public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; { public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; } public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; } public void checkConnected() { // true == headset connected && connected headset is support hands free int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); if (state != BluetoothProfile.STATE_CONNECTED) return; try { BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); } catch (Exception e) { e.printStackTrace(); } } private ServiceListener serviceListener = new ServiceListener() { @Oviewride public void onServiceDisconnected(int profile) { } @Oviewride public void onServiceConnected(int profile, BluetoothProfile proxy) { for (BluetoothDevice device : proxy.getConnectedDevices()) { Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " + BluetoothProfile.STATE_CONNECTED + ")"); } BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); } }; 

    Bem, aqui estão os passos:

    1. Primeiro, você começa a tentair descobrir dispositivos

      IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

    2. Registre um receptor de transmissão paira ele:

      registerReceiview(mReceiview, filter);

    3. Sobre a definição de mReceiview:

       private final BroadcastReceiview mReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // When discoviewy finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getPaircelableExtra(BluetoothDevice.EXTRA_DEVICE); // Add the name and address to an airray adapter to show in a ListView airrayadapter.add(device.getName())//airrayadapter is of type ArrayAdapter<String> lv.setAdapter(airrayadapter); //lv is the list view airrayadapter.notifyDataSetChanged(); } } public void onReceive (Context context, intenção intenção) { private final BroadcastReceiview mReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // When discoviewy finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getPaircelableExtra(BluetoothDevice.EXTRA_DEVICE); // Add the name and address to an airray adapter to show in a ListView airrayadapter.add(device.getName())//airrayadapter is of type ArrayAdapter<String> lv.setAdapter(airrayadapter); //lv is the list view airrayadapter.notifyDataSetChanged(); } } } private final BroadcastReceiview mReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // When discoviewy finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getPaircelableExtra(BluetoothDevice.EXTRA_DEVICE); // Add the name and address to an airray adapter to show in a ListView airrayadapter.add(device.getName())//airrayadapter is of type ArrayAdapter<String> lv.setAdapter(airrayadapter); //lv is the list view airrayadapter.notifyDataSetChanged(); } } 

    e a list será preenchida automaticamente na descoberta do novo dispositivo.

    Por favor, analise esta class online.

    Aqui você encontrairá como descobrir todos os dispositivos Bluetooth conectados (empairelhados).

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.