Reputation: 2829
I am developing a demo app to scan Blutooth Le devices. But startLeScan() returns null. and I am not getting any device name. I have tried using normal scan it shows up fine. I am adding my snippet here
private void scanLeDevice(final boolean enable) {
if (enable) {
// Stops scanning after a pre-defined scan period.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mScanning = false;
mTxtInfo.setText("Stopped Scanning.");
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}, SCAN_PERIOD);
mScanning = true;
mTxtInfo.setText("Started Scanning...");
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
mTxtInfo.setText("Stopped Scanning.");
mScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}
This is my function to start Le scan.
// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi,
byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mTxtInfo.setText("Detected devices: " + device.getName());
Toast.makeText(MainActivity.this,
"Detected devices: " + device.getName(),
Toast.LENGTH_LONG).show();
}
});
}
};
this is the callback. And its showing me
07-04 12:50:17.833: D/BluetoothAdapter(3564): startLeScan(): null
Would appreciate any help.
Upvotes: 0
Views: 1595
Reputation: 33
The Problem there is that you are trying to use
startLeScan(callback)
without setting the Uuid parameter. So the BluetoothAdapter code it's doing something like:
startLeScan(null, callback)
on the back and printing
"startLeScan:" + Uuid.
Which for you is null.
Upvotes: 2