SyncMr
10-28-2011, 12:33 AM
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_DE VICE);Log.v("BlueTooth Testing",device.getName() + "\n"+ device.getAddress()); }} };String aDiscoverable = BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;start ActivityForResult(new Intent(aDiscoverable),DISCOVERY_REQUEST);IntentFil ter 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.
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_DE VICE);Log.v("BlueTooth Testing",device.getName() + "\n"+ device.getAddress()); }} };String aDiscoverable = BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;start ActivityForResult(new Intent(aDiscoverable),DISCOVERY_REQUEST);IntentFil ter 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.