Blutooth LE Scan

I am developing a demo application for scanning Blutooth Le devices. But startLeScan () returns null. and I do not get any device name. I tried using conventional scanning, it is clearly visible. I add my fragment 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 run 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 a callback. And showing me

 07-04 12:50:17.833: D/BluetoothAdapter(3564): startLeScan(): null 

Would thank for any help.

0
android bluetooth bluetooth-lowenergy
source share
1 answer

The problem is that you are trying to use

 startLeScan(callback) 

without setting the Uuid parameter. So the bluetoothadapter code does something like:

 startLeScan(null, callback) 

on the back and print

 "startLeScan:" + Uuid. 

What is null for you.

+2
source share

All Articles