Bluetooth 没有虚拟方法的应用程序craches isLe2MPhySupported()

Bluetooth 没有虚拟方法的应用程序craches isLe2MPhySupported(),bluetooth,Bluetooth,我想知道smarphone是否可以用以下代码处理编码的py。 在手机上,witch可以处理编码的py,它工作正常并与编码的py连接。 在无法处理编码py的手机上,它会在“if(btAdapter.isLeCodedPhySupported())”行处崩溃。有人能帮我解决这个问题吗 @RequiresApi(api = Build.VERSION_CODES.O) public void startScanning() { if(btAdapter.isLeCodedPhySupporte

我想知道smarphone是否可以用以下代码处理编码的py。 在手机上,witch可以处理编码的py,它工作正常并与编码的py连接。 在无法处理编码py的手机上,它会在“if(btAdapter.isLeCodedPhySupported())”行处崩溃。有人能帮我解决这个问题吗

@RequiresApi(api = Build.VERSION_CODES.O)
public void startScanning() {
    if(btAdapter.isLeCodedPhySupported()){
        isCodedCapable=true;
        Log.w(TAG, "IsCodedCapable");
    }
    else Log.w(TAG, "Is NOT CodedCapable");
    final ScanSettings settings;
    final List<ScanFilter> filters = new ArrayList<>();
    if (isCodedCapable) {
        Log.w(TAG, "settingsCoded");
        settings = new ScanSettings.Builder()
        .setPhy(ScanSettings.PHY_LE_ALL_SUPPORTED)
        .setScanMode(ScanSettings.SCAN_MODE_BALANCED)
        .setLegacy(false)
        .build();
    }
    else {
        Log.w(TAG, "settingsLegasy");
        settings = new ScanSettings.Builder()
        .setScanMode(ScanSettings.SCAN_MODE_BALANCED)
        .build();
}

    AsyncTask.execute(new Runnable() {
        @Override
        public void run() {
            btScanner.startScan( filters, settings, leScanCallback);
        }
    });

    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            stopScanning();
        }
    }, 5000;
}
@RequiresApi(api=Build.VERSION\u CODES.O)
公共无效开始扫描(){
if(btAdapter.isLeCodedPhySupported()){
isCodedCapable=true;
Log.w(标记为“IsCodedCapable”);
}
else Log.w(标记“不可编码”);
最终扫描设置;
最终列表过滤器=新的ArrayList();
if(isCodedCapable){
Log.w(标记“设置范围”);
设置=新的ScanSettings.Builder()
.setPhy(ScanSettings.PHY\u LE\u所有受支持)
.setScanMode(扫描设置.SCAN\u模式\u平衡)
.setLegacy(错误)
.build();
}
否则{
Log.w(标记为“settingsLegasy”);
设置=新的ScanSettings.Builder()
.setScanMode(扫描设置.SCAN\u模式\u平衡)
.build();
}
AsyncTask.execute(新的Runnable(){
@凌驾
公开募捐{
btScanner.startScan(过滤器、设置、leScanCallback);
}
});
mHandler.postDelayed(新的Runnable(){
@凌驾
公开募捐{
停止扫描();
}
}, 5000;
}
事实证明,SDK 26支持“islecodephysupported()”,我的手机是SDK 23。编辑代码如下。现在运行正常

    if(Build.VERSION.SDK_INT<26)isCodedCapable = false;
    else {
        if (btAdapter.isLeCodedPhySupported()) {
            isCodedCapable = true;
            Log.w(TAG, "IsCodedCapable");
        } else Log.w(TAG, "Is NOT CodedCapable");
    }
if(Build.VERSION.SDK\u INT