Android Development -Discovering available bluetooth devices in eclipse

Pragadheesh

Disciple
Hi,

I just started learning android development. I am writing an android program to scan available bluetooth devices and list them in a log file and later find the strength of the bluetooth signals.

Below is a code snippet for Finding available bluetooth devices. As I am new to android, I am unable to figure out what is wrong in the code.

button2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
ListView lv1 = (ListView) findViewById(R.id.myListView1);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();


final BroadcastReceiver mReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action))
{
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(
BluetoothDevice.EXTRA_DEVICE);
Log.v("BlueTooth Testing",device.getName() + "\n"
+ device.getAddress());
}
}
};

String aDiscoverable = BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
startActivityForResult(new Intent(aDiscoverable),DISCOVERY_REQUEST);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
mBluetoothAdapter.startDiscovery();
}
});

When I try the debug mode, the control skips the "BroadcastReceiver()". I could not find any entries in the log. Can you help me in figuring out what the problem is and how I can list the available bluetooth devices.

--- Updated Post - Automerged ---

gentle bounce. any comments or suggestions please
 
Hi,

Please state your eclipse version and ADT plugin version.

Also are you using a device to do development? Which device you are using and what's the OS version?
 
Back
Top