gpt4 book ai didi

java - NoSuchMethod 异常

转载 作者:行者123 更新时间:2023-11-30 10:42:08 26 4
gpt4 key购买 nike

我使用的是 BLE startLescan 但它现在已经过时了。现在我已将我的 API 级别更改为 23(从 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 throws a nosuchmethod exception:

method lookup failed for selector "getBluetoothLeScanner" with signature "()Landroid/bluetooth/le/BluetoothLeScanner;"

最佳答案

在这种情况下需要一个 BluetoothAdapter 的实例。做这样的事情:

Context mContext = getBaseContext();
BluetoothAdapter mBluetoothAdapter = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE).getAdapter();
BluetoothLeScanner mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();

mBluetoothLeScanner.startScan(new ScanCallback() {….

}

关于java - NoSuchMethod 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38236593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com