title: Discovery for bluetooth devices does not work
body: <p>I am trying to give to my app the feature of bond with new devices but my code does not work and i do not have any crash</p>
  
  <pre><code>
  
          package com.kyuukun.boltcontroller.Command;
  
      import android.app.Activity;
      import android.bluetooth.BluetoothAdapter;
      import android.bluetooth.BluetoothDevice;
      import android.bluetooth.BluetoothSocket;
      import android.content.BroadcastReceiver;
      import android.content.Context;
      import android.content.Intent;
      import android.content.IntentFilter;
      import android.util.Log;
  
      import java.io.IOException;
      import java.io.InputStream;
      import java.util.ArrayList;
      import java.util.UUID;
  
      public class DataControl
      {
          private BluetoothAdapter btadapter;
          private ArrayList paired = new ArrayList();;
          private BluetoothDevice connected;
          private BluetoothSocket socket;
          private BroadcastReceiver receiver;
  
          public DataControl(BluetoothAdapter adapter)
          {
              this.btadapter = adapter;
          }
  
          public BluetoothAdapter getAdapter()
          {
              return btadapter;
          }
  
          public ArrayList getPaired()
          {
              return paired;
          }
  
          public void startPaired(Activity act)
          {
  
              if(!btadapter.getBondedDevices().isEmpty())
              {
                  for(BluetoothDevice d : btadapter.getBondedDevices())
                  {
                      paired.add(d);
                  }
              }
  
              btadapter.startDiscovery();
  
              IntentFilter filter = new IntentFilter();
  
              filter.addAction(BluetoothDevice.ACTION_FOUND);
              filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
              filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
  
              BroadcastReceiver r = new BroadcastReceiver()
              {
                  @Override
                  public void onReceive(Context context, Intent intent)
                  {
                      String action = intent.getAction();
  
                      Log.d("SENPAI", action);
  
                      if (BluetoothDevice.ACTION_FOUND.equals(action))
                      {
                          BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
  
                          paired.add(device);
  
                      } else {}
                  }
              };
  
              act.registerReceiver(r, filter);
  
              receiver = r;
  
          }
  
  
          public boolean startConnection(BluetoothDevice device)
          {
              boolean c = false;
  
              if(paired.contains(device))
              {
  
                  BluetoothSocket sck;
  
                  try {
                      sck = device.createRfcommSocketToServiceRecord(UUID.randomUUID());
                      sck.connect();
                      this.socket = sck;
                      this.connected = device;
                      c = true;
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
  
              }
  
              return c;
          }
  
          public BroadcastReceiver getReceiver()
          {
              return receiver;
          }
  
          public boolean send(String s)
          {
  
              boolean sd = false;
  
              if(connected != null && socket != null)
              {
                  try {
                      socket.getOutputStream().write(s.getBytes());
                      sd = true;
                  } catch (IOException e) {
                      e.printStackTrace();
                      sd = false;
                  }
              }
  
              return sd;
          }
  
          public String getData()
          {
              String s = "";
  
              if(connected != null && socket != null)
              {
                  InputStream stream;
  
                  try {
                      stream = socket.getInputStream();
  
                      if(stream.available() > 0)
                      {
                          byte[] b = new byte[stream.available() + 1];
  
                          stream.read(b);
  
                          String newstring = new String(b);
  
                          s.concat(newstring);
                      }
  
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
  
              }
  
              return s;
          }
  
  
  
  
  
  
          }
  
  </code></pre>
  
  <p>Code on activity:</p>
  
  <pre><code>
  
      MainActivity.control.startPaired(LoadingActivity.this);
  
                                  if(MainActivity.control.getPaired().size() > 0)
                                  {
                                      MainActivity.control.getAdapter().cancelDiscovery();
                                      Intent intent = new Intent(LoadingActivity.this, PairedDevicesActivity.class);
                                      startActivity(intent);
                                      finish();
                                      break;
  
                                  }
  
  </code></pre>
  
  <p>What i receive on Log:</p>
  
  <p>08-27 22:38:36.049 26687-26687/com.kyuukun.boltcontroller D/SENPAI: android.bluetooth.adapter.action.DISCOVERY_STARTED</p>
  
  <p>When i get the bonded divices it works fine but when i try to get new devices it does not do nothing.</p>