Android Bluetooth rescanning cause Bluetooth lost

141 views Asked by At

I am working on Bluetooth related application where I provide user a list of nearby Bluetooth devices and also I provide a rescan button to restart scanning process. When user comes to this view application start discovery process and if application founds device it get display in a list. But if the user presses rescan button, first application clear list and then restart scanning process then application fails to list same device again. I don't know why application fails to rescan same device again.

2

There are 2 answers

0
Abhijit Muke On

Check out code below :

Starting search

mBluetoothAdapter.startDiscovery(); 
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();

Finding devices

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);
0
Easy Rider On

The Discovery procedure is in some sense a probabilistic, so if you can't get identical lists in two sequential calls it is ok. I'd rather wonder are you able to enumerate any other BT-devices during subsequent calls. And if answer is always 'yes', and you experience problems with that only device, check if it is operating correctly. If after first successful call you can't enumerate the devices - either your code is incorrect or your device you're using for debugging works not very well (that's happens quite often in the Android World).