【发布时间】:2016-07-12 18:01:39
【问题描述】:
我使用的是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/bluetooth/le/BluetoothLeScanner;”
【问题讨论】:
-
向我们展示
startScan方法上面的代码。你是如何初始化mBluetoothAdapter的?/
标签: java android android-5.0-lollipop bluetooth-lowenergy nosuchmethoderror