我使用的是BLE startLescan,但现在它已经过时了。现在,我已经更改了我的API level to 23 (from 20),并为此使用了BluetoothLeScanner。我的开始扫描功能是:
public void startScan(){
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
mBluetoothLeScanner.startScan(new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
String s = "\nRssi : "+result.getRssi()+"" +
"\nName (Get Device) : "+result.getDevice().getName()+"" +
"\nBytes"+result.getScanRecord().getBytes()+"" +
"\nGet Device : " + result.getDevice()+"" +
"\nAddress : "+result.getDevice().getAddress()+"" +
"\nService UUIds : "+result.getScanRecord().getServiceUuids().get(0)+"" + //Unique
"\nName (Scan Record) : "+result.getScanRecord().getDeviceName()+"" +
"\nUuids device : "+result.getDevice().getUuids()+"" +
"\nDescribe contents : "+result.describeContents();
//This will show you all the data in logs.
Log.e("All Data",s);
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
}
});当我到达第一行时,
java抛出一个nosuchmethod异常: 方法查找失败的选择器"getBluetoothLeScanner“与签名”()Landroid/蓝牙/le/蓝牙刷扫描仪;
发布于 2016-07-12 10:01:39
如果您的设备有API版本20或更低,它将无法使用新的API。因此,您需要实现两种扫描方法,并根据设备os版本检查应该使用哪个版本。(Kitkat不支持新的扫描API!)
发布于 2016-07-07 02:15:26
在这种情况下,需要一个BluetoothAdapter实例。做这样的事:
Context mContext = getBaseContext();
BluetoothAdapter mBluetoothAdapter = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE).getAdapter();
BluetoothLeScanner mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
mBluetoothLeScanner.startScan(new ScanCallback() {….
}https://stackoverflow.com/questions/38236593
复制相似问题