来自宏碁平板电脑的错误日志,宏碁B1-810android 4.4.4我正在测试小的BLE应用程序,我得到了这个日志“找不到方法android.bluetooth.le.BluetoothLeScanner.startScan ",我很困惑,因为BLE是在API18 (4.3)中引入的,这里我使用的是安卓4.4.4,但是”找不到方法android.bluetooth.le.BluetoothLeScanner.startScan“。它显示在日志中。
发布于 2016-04-21 23:18:03
使用BluetoothAdapter.startLeScan()在21版本以下的应用编程接口中添加了BluetoothLeScanner
private void startBluetoothLeScan() {
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
if (Build.VERSION.SDK_INT < 21) {
bluetoothAdapter.startLeScan(new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
}
});
} else {
BluetoothLeScanner bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
ScanSettings scanSettings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.build();
List<ScanFilter> scanFilters = new ArrayList<>();
bluetoothLeScanner.startScan(scanFilters, scanSettings, new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
}
});
}
}有关详细信息,请参阅Bluetooth Low Energy文档
https://stackoverflow.com/questions/36762549
复制相似问题