蓝牙低能量的扫描失败 [英] Scanning of Bluetooth Low Energy Fails

查看:160
本文介绍了蓝牙低能量的扫描失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发将使用蓝牙低耗能的应用程序。

我使用下面的链接,

<一个href="http://developer.android.com/samples/BluetoothLeGatt/src/com.example.android.bluetoothlegatt/DeviceScanActivity.html" rel="nofollow">http://developer.android.com/samples/BluetoothLeGatt/src/com.example.android.bluetoothlegatt/DeviceScanActivity.html

我不能够扫描周围的BLE装置。

要扫描设备,

  mBluetoothAdapter.startLeScan(mLeScanCallback);

私人BluetoothAdapter.LeScanCallback mLeScanCallback =新BluetoothAdapter.LeScanCallback()
    {

        @覆盖
        公共无效onLeScan(最终BluetoothDevice类设备,INT RSSI,byte []的scanRecord)
        {

            runOnUiThread(新的Runnable(){
                @覆盖
                公共无效的run()
                {

                    mLeDeviceListAdapter.addDevice(设备);

                    mLeDeviceListAdapter.notifyDataSetChanged();

                }
            });
        }
    };
 

解决方案

我有同样的问题,请将这些权限添加到您的清单

 &LT;使用-权限的Andr​​oid:名称=android.permission.BLUETOOTH/&GT;
&LT;使用-权限的Andr​​oid:名称=android.permission.BLUETOOTH_ADMIN/&GT;
 

I am currently developing an application that will use Bluetooth Low Energy.

I am using the following link,

http://developer.android.com/samples/BluetoothLeGatt/src/com.example.android.bluetoothlegatt/DeviceScanActivity.html

I am not able to scan the surrounding BLE devices.

To scan device,

mBluetoothAdapter.startLeScan(mLeScanCallback); 

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

        @Override
        public void onLeScan(final BluetoothDevice device, int rssi,byte[] scanRecord) 
        {

            runOnUiThread(new Runnable() {
                @Override
                public void run() 
                {

                    mLeDeviceListAdapter.addDevice(device);

                    mLeDeviceListAdapter.notifyDataSetChanged();

                }
            });
        }
    };

解决方案

I had the same problem please add these permissions to your manifest

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

这篇关于蓝牙低能量的扫描失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆