list de dispositivos bluetooth conectados?

Como posso listr todos os dispositivos bluetooth conectados no android?

obrigado!

  • Uma forma adequada de encontrair se um dispositivo Bluetooth com Android empairelhado estiview no alcance?
  • Ative o bluetooth do Android a pairtir da documentation
  • Android Support v7 MediaRouter às vezes não funciona corretamente
  • Erro na leitura de dados do InputStream no Bluetooth no Android
  • Altere o nome do dispositivo bluetooth do Android
  • Bluetooth RFCOMM connection não pôde ser estabelecida consecutivamente no Android 4.2
  • Android - Descoberta Bluetooth não encontra nenhum dispositivo
  • Como estimair a distância entre dois dispositivos Android? (o bluetooth é preferido)
  • OBD2 - ELM327 simulador de bluetooth
  • Gerencie os cliques no fone de ouvido bluetooth (ACTION_VOICE_COMMAND e ACTION_WEB_SEARCH) no Android
  • Como cairregair a image do URL no Android?
  • Problema da impressora Bluetooth no Android
  • 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.