Foros del Web » Programando para Internet » Android »

Mostrar dispositivos bluetooth

Estas en el tema de Mostrar dispositivos bluetooth en el foro de Android en Foros del Web. Buenas! Estoy intentando crear una app sencilla donde activar el bluetooth, y buscar los dispositivos que encuentre. He seguido mas o menos los pasos de ...
  #1 (permalink)  
Antiguo 20/04/2016, 04:59
 
Fecha de Ingreso: mayo-2009
Mensajes: 232
Antigüedad: 15 años
Puntos: 3
Mostrar dispositivos bluetooth

Buenas!

Estoy intentando crear una app sencilla donde activar el bluetooth, y buscar los dispositivos que encuentre.

He seguido mas o menos los pasos de developer.android, y todo correcto hasta el momento que quiero mostrar los dispositivos.

No me da ningún error y la app no falla en ni ningún momento, pero no se ven las listas.
Si pongo un toast justo después del if donde debo ir recibiendo los dispositivos, no se ejecta, si lo pongo justo antes si.

Código Java:
Ver original
  1. buscarBl.setOnClickListener(new View.OnClickListener() {
  2.             public void onClick(View v) {
  3.  
  4.                 Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
  5.  
  6.                 if (pairedDevices.size() >= 0) {
  7.                     Toast.makeText(getBaseContext(), "Your answer is correct!" , Toast.LENGTH_SHORT ).show();
  8.                     // Loop through paired devices
  9.                     for (BluetoothDevice device : pairedDevices) {
  10.                         // Add the name and address to an array adapter to show in a ListView
  11.                         listaBlue.add(device.getName() + "\n" + device.getAddress());
  12.                     }
  13.  
  14.                     listaDispositius = (ListView)findViewById(R.id.llistaDisp);
  15.                     ArrayAdapter<String> adaptador = new ArrayAdapter<>(MainActivity.this,android.R.layout.simple_list_item_1, listaBlue);
  16.                     listaDispositius.setAdapter(adaptador);
  17.                 }
  18.  
  19.  
  20.                 // Create a BroadcastReceiver for ACTION_FOUND
  21.                 final BroadcastReceiver mReceiver = new BroadcastReceiver() {
  22.                     public void onReceive(Context context, Intent intent) {
  23.                         String action = intent.getAction();
  24.                         // When discovery finds a device
  25.                         if (BluetoothDevice.ACTION_FOUND.equals(action)) {
  26.                             // Get the BluetoothDevice object from the Intent
  27.                             BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
  28.                             // Add the name and address to an array adapter to show in a ListView
  29.                             listaBlue.add(device.getName() + "\n" + device.getAddress());
  30.                         }
  31.                         listaDispositius = (ListView)findViewById(R.id.llistaDisp);
  32.                         ArrayAdapter<String> adaptador = new ArrayAdapter<>(MainActivity.this,android.R.layout.simple_list_item_1, listaBlue);
  33.                         listaDispositius.setAdapter(adaptador);
  34.                     }
  35.                 };
  36. // Register the BroadcastReceiver
  37.                 IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
  38.                 registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
  39.  
  40.             }
  41.         });
  #2 (permalink)  
Antiguo 06/05/2016, 12:40
Avatar de loganbdn  
Fecha de Ingreso: enero-2009
Ubicación: Badalona
Mensajes: 114
Antigüedad: 15 años, 3 meses
Puntos: 1
Respuesta: Mostrar dispositivos bluetooth

Hola, yo estoy haciendo pruebas tambien con el bluetooth. Para hacerlo mas sencillo y luego ir complicandolo creo que lo mejor es sabiendo la MAC del dispositivo bluetooth rastrear si esta visible o no y que devuelva un true (visible ) o false ( no visible ). Pero no encuentro el metodo que haria eso.

Etiquetas: bluetooth, java
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:05.