title: Program to discover bluetooth devices in range and display them in android
body: <p>I want to design a bluetooth remote but when I click on the search button it does not search for the devices, or maybe it does but does not show any of them.</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      final Button button1 = (Button) findViewById(R.id.button1);
      final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
      final ArrayAdapter&lt;String&gt; mArrayAdapter=new ArrayAdapter&lt;String&gt;(this,R.layout.activity_main);
      button1.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              // TODO Auto-generated method stub
              if(!mBluetoothAdapter.isEnabled())
              {
                  Intent enableBtIntent=new 
                          Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                  startActivityForResult(enableBtIntent,REQUEST_ENABLE_BT);
              }
              mBluetoothAdapter.startDiscovery(); 
              BroadcastReceiver mReceiver = new BroadcastReceiver() {
              public void onReceive(Context context, Intent intent) {
                  String action = intent.getAction();
                  if (BluetoothDevice.ACTION_FOUND.equals(action)) 
                  {
                      // Get the BluetoothDevice object from the Intent
                      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                      // Add the name and address to an array adapter to show in a ListView
                     mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
                  }
                }
              };
  
              IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
              registerReceiver(mReceiver, filter);
          }
      });
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  }
  </code></pre>