[英]BluetoothAdapter.startLeScan is not working with filter
private UUID[] RX_SERVICE_UUID = new UUID[1];
RX_SERVICE_UUID[0] = UUID.fromString("0000e4eee-1112-1111-1111-14addb4as215");
when i am using the function with UUID mBluetoothAdapter.startLeScan(RX_SERVICE_UUID,mLeScanCallback)
method.当我使用带有 UUID
mBluetoothAdapter.startLeScan(RX_SERVICE_UUID,mLeScanCallback)
方法的函数时。 It is not scanning the device when i am using without UUID means mBluetoothAdapter.startLeScan(mLeScanCallback)
then it is scanning the device.当我在没有 UUID 的情况下使用时,它不扫描设备意味着
mBluetoothAdapter.startLeScan(mLeScanCallback)
然后它正在扫描设备。 Please suggest.请建议。
I think you are testing app in marshmallow我认为您正在棉花糖中测试应用程序
for scaning any ble device required some permission扫描任何 ble 设备需要一些许可
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:name="android.hardware.bluetooth_le" />
enable bluetooth启用蓝牙
// Ensures Bluetooth is enabled on the device. If Bluetooth is not currently enabled,
// fire an intent to display a dialog asking the user to grant permission to enable it.
if (!mBluetoothAdapter.isEnabled()) {
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
// Initializes list view adapter.
mLeDeviceListAdapter = new LeDeviceListAdapter();
mLeDevicePairedListAdapter = new LeDevicePairedListAdapter();
setListAdapter(mLeDeviceListAdapter);
setPairedListAdapter(mLeDevicePairedListAdapter);
scanLeDevice(true);
start scaning by using this method使用此方法开始扫描
private void scanLeDevice(final boolean enable) {
if (enable) {
mScanning = true;
selectedPositions = new ArrayList<>();
pairselectedPositions = new ArrayList<>();
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
mScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
// invalidateOptionsMenu();
}
callbackresponse回调响应
// Device scan callback. // 设备扫描回调。
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
//if device bounded then added another list and not bound then using other list diplay in list
if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
mLeDevicePairedListAdapter.addDevice(device, rssi);
} else {
mLeDeviceListAdapter.addDevice(device, rssi);
}
}
});
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.