Android棉花糖中未调用BluetoothAdapter.LeScanCallback上的onLeScan

Android棉花糖中未调用BluetoothAdapter.LeScanCallback上的onLeScan,第1张

概述我刚刚更新了Nexus5,但我的应用功能已停止运行.原因是接口LeScanCallback没有调用onLeScan函数.在下面的代码中,我正在使用一些不推荐使用的代码,但是由于我正在测试某些技术,因此需要这样做.这是我启动蓝牙适配器的方式:@OverrideprotectedvoidonStart(){super.onStar

我刚刚更新了Nexus 5,但我的应用功能已停止运行.

原因是接口LeScanCallback没有调用onLeScan函数.在下面的代码中,我正在使用一些不推荐使用的代码,但是由于我正在测试某些技术,因此需要这样做.这是我启动蓝牙适配器的方式:

@OverrIDeprotected voID onStart(){    super.onStart();    // Check if the device has BLE    if (!this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUetoOTH_LE))    {        bleNotSupported();        return;    }    // Initializes a Bluetooth adapter.    final BluetoothManager bluetoothManager = (BluetoothManager)this.getSystemService(Context.BLUetoOTH_SERVICE);    mBluetoothAdapter = bluetoothManager.getAdapter();    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled())    {        bleNotEnabled();        /*        * Bluetooth can be enabled in app:        *        *    Intent btIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);        *    btIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        *    mAppContext.startActivity(btIntent);        */        return;    }    boolean bluetoothScanning = mBluetoothAdapter.startLeScan(mScanCallback); // this is true as well    progressbar.setVisibility(VIEw.VISIBLE);}@OverrIDeprotected voID onStop() {    super.onStop();    if (mBluetoothAdapter != null)    {        mBluetoothAdapter.stopLeScan(mScanCallback);    }    progressbar.setVisibility(VIEw.GONE);    mDeviceAdapter.clearList();}BluetoothAdapter.LeScanCallback mScanCallback = new BluetoothAdapter.LeScanCallback() {    @OverrIDe    public voID onLeScan(final BluetoothDevice device, int RSSi, byte[] scanRecord)    {//            if (prevIoUsBluetoothSelected == null)        mDeviceAdapter.refreshList(device);        if (device.getAddress().equalsIgnoreCase(prevIoUsBluetoothSelected)) {            selectDeviceAndGo(device);            mBluetoothAdapter.stopLeScan(this);        }    }};

并且它可以在每个具有API< 23,但不是API = 23.可能是什么原因?提前非常感谢您.问候.拉斐尔.

解决方法:

某些配备棉花糖的Nexus 5手机存在错误.在某些手机中,如果您的gps已关闭,则扫描不会开始.

总结

以上是内存溢出为你收集整理的Android棉花糖中未调用BluetoothAdapter.LeScanCallback上的onLeScan全部内容,希望文章能够帮你解决Android棉花糖中未调用BluetoothAdapter.LeScanCallback上的onLeScan所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1093512.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存