pair two bluetooth devices programaticaly
<p>i am doing a bluetooth project in which i want to pair two bluetooth devices programaticaly in android.I am using default api in android.It is finding devices.But does not return Action_found intent.While checking the condition for the action_found intent,it returns false.But in logcat it shows the found devices adress.Here is the sample code i tried.Can anyone remove this bug?</p>

<pre><code>package com.qburst.android.settingsmanager.view;

import java.util.ArrayList;
import java.util.Set;



import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Toast;

public class Bluetooth extends Activity {
    protected static final int REQUEST_ENABLE_BT = 1;
    private View mBluetooth;
    private Button mOnButton;
    private Button mActiveDevices;
    private Button mDiscoverable;
     public ArrayAdapter&lt;String&gt; mArrayAdapter;
     public BluetoothAdapter mBluetoothAdapter;
     ArrayList&lt;String&gt; devices = new ArrayList&lt;String&gt;();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    setContentView(R.layout.bluetooth);
    mOnButton = (Button) findViewById(R.id.on_button);
    mActiveDevices = (Button) findViewById(R.id.active_devices);
    mDiscoverable = (Button) findViewById(R.id.discoverable_button);
    mArrayAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.main);
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    registerReceiver(mReceiver, filter);


    mOnButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
              mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
              if (mBluetoothAdapter == null) {
                  // Device does not support Bluetooth
              }
              if (!mBluetoothAdapter.isEnabled()) {
                    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
                }

        }
    });


    mActiveDevices.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

             Set&lt;BluetoothDevice&gt; pairedDevices = mBluetoothAdapter.getBondedDevices();
             System.out.println("checking paired devices");
          // If there are paired devices
          if (pairedDevices.size() &gt; 0) {
              System.out.println(" paired devices");
              // Loop through paired devices
              for (BluetoothDevice device : pairedDevices) {
                  // Add the name and address to an array adapter to show in a ListView
                  mArrayAdapter.add(device.getName() + "\n" + device.getAddress());

              }
          }else {
              mBluetoothAdapter.startDiscovery();
          }


        }
    });

    mDiscoverable.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
             Intent discoverableIntent = new
                     Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
                     discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
                     startActivity(discoverableIntent);

          }



    });

    }

     public void onActivityResult(int requestCode, int resultCode, Intent data) {

            switch (requestCode) {


            case REQUEST_ENABLE_BT:
                // When the request to enable Bluetooth returns
                if (resultCode == Activity.RESULT_OK) {
                    Toast.makeText(this, "Bluetooth enebled", Toast.LENGTH_SHORT).show();

                } else {
                    // User did not enable Bluetooth or an error occurred

                    Toast.makeText(this, "Bluetooth not enebled", Toast.LENGTH_SHORT).show();
                    finish();
                }
            }
        }


     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {

            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                devices.add(device.getName());
                   devices.add(device.getAddress());
                   System.out.println(devices);
                // When discovery finds a device
                Log.i("receiver","Inside receiver");

                if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                    System.out.println("device found");
                    Toast.makeText(getBaseContext(), "No device found",Toast.LENGTH_LONG);
                    // 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
                   System.out.println(device.getName());
                   devices.add(device.getName());
                   devices.add(device.getAddress());
                   mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
                   System.out.println(devices);
                }


            }
        };


        // Register the BroadcastReceiver

        // Don't forget to unregister during onDestroy
        @Override
        protected void onDestroy() {

            super.onDestroy();
        }


}
</code></pre>

<p>Thanks in Advance</p>
