简体   繁体   English

BluetoothAdapter.startLeScan 不适用于过滤器

[英]BluetoothAdapter.startLeScan is not working with filter

private UUID[] RX_SERVICE_UUID = new UUID[1]; 
RX_SERVICE_UUID[0] = UUID.fromString("0000e4eee-1112-1111-1111-14addb4as215");

when i am using the function with UUID mBluetoothAdapter.startLeScan(RX_SERVICE_UUID,mLeScanCallback) method.当我使用带有 UUID mBluetoothAdapter.startLeScan(RX_SERVICE_UUID,mLeScanCallback)方法的函数时。 It is not scanning the device when i am using without UUID means mBluetoothAdapter.startLeScan(mLeScanCallback) then it is scanning the device.当我在没有 UUID 的情况下使用时,它不扫描设备意味着mBluetoothAdapter.startLeScan(mLeScanCallback)然后它正在扫描设备。 Please suggest.请建议。

I think you are testing app in marshmallow我认为您正在棉花糖中测试应用程序

for scaning any ble device required some permission扫描任何 ble 设备需要一些许可

  <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-feature android:name="android.hardware.bluetooth_le" />

enable bluetooth启用蓝牙

 // Ensures Bluetooth is enabled on the device.  If Bluetooth is not currently enabled,
        // fire an intent to display a dialog asking the user to grant permission to enable it.
        if (!mBluetoothAdapter.isEnabled()) {
            if (!mBluetoothAdapter.isEnabled()) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
            }
        }

        // Initializes list view adapter.
        mLeDeviceListAdapter = new LeDeviceListAdapter();
        mLeDevicePairedListAdapter = new LeDevicePairedListAdapter();
        setListAdapter(mLeDeviceListAdapter);
        setPairedListAdapter(mLeDevicePairedListAdapter);
        scanLeDevice(true);

start scaning by using this method使用此方法开始扫描

 private void scanLeDevice(final boolean enable) {
        if (enable) {
            mScanning = true;
            selectedPositions = new ArrayList<>();
            pairselectedPositions = new ArrayList<>();
            mBluetoothAdapter.startLeScan(mLeScanCallback);
        } else {
            mScanning = false;
            mBluetoothAdapter.stopLeScan(mLeScanCallback);
        }
//        invalidateOptionsMenu();
    }

callbackresponse回调响应

// Device scan callback. // 设备扫描回调。

private BluetoothAdapter.LeScanCallback mLeScanCallback =
        new BluetoothAdapter.LeScanCallback() {

            @Override
            public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
//if device bounded then added another list and not bound then using other list diplay in list
                        if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
                            mLeDevicePairedListAdapter.addDevice(device, rssi);
                        } else {
                            mLeDeviceListAdapter.addDevice(device, rssi);
                        }
                    }
                });
            }
        };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的BluetoothAdapter.startLeScan()在Lollipop API21中无法正常工作 - My BluetoothAdapter.startLeScan() is not working properly in Lollipop API21 BluetoothAdapter.startScan()vs BluetoothAdapter.startLeScan() - BluetoothAdapter.startScan() vs BluetoothAdapter.startLeScan() Android物件(Raspberry Pi 3)BluetoothAdapter.startLEScan(..) - Android things (Raspberry Pi 3) BluetoothAdapter.startLEScan(..) 为什么我的RxJava安装程序阻止了我的UI线程? 使用BluetoothAdapter.startLeScan回调 - Why my RxJava setup is blocking my UI thread? Working with BluetoothAdapter.startLeScan callback Xamarin Android BLE-BluetoothAdapter.StartLeScan返回false - Xamarin Android BLE - BluetoothAdapter.StartLeScan returning false BluetoothLE BluetoothAdapter:startLeScan():空 - BluetoothLE BluetoothAdapter﹕ startLeScan(): null BluetoothAdapter.getDefaultAdapter().startDiscovery() 不工作 - BluetoothAdapter.getDefaultAdapter().startDiscovery() not working registerReceiver BluetoothAdapter.ACTION_STATE_CHANGED不起作用 - registerReceiver BluetoothAdapter.ACTION_STATE_CHANGED not working Android BluetoothAdapter禁用功能在设备2.3.6上不起作用 - Android BluetoothAdapter Disable function not working on Device 2.3.6 Android BluetoothAdapter.LeScanCallback onLeScan 方法在 BluetoothLeScanner 工作时未调用 - Android BluetoothAdapter.LeScanCallback onLeScan method not called while BluetoothLeScanner working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM