我正在使用蓝牙低功耗(BLE)的方式,尝试通过Android应用程序连接Arduino Uno。
我在Android Studio上开发,在一个运行着Android 5.0.1的三星Galaxy S4上进行测试。
我按照这个链接:http://www.truiton.com/2015/04/android-bluetooth-low-energy-ble-example/ 的指引操作。
我正在扫描设备,当找到一个设备时,我想在连接它之前获取其UUID,以确保它是正确类型的设备:
mScanCallback = new ScanCallback() {
@Override
@TargetApi(21)
public void onScanResult(int callbackType, ScanResult result) {
BluetoothDevice btDevice = result.getDevice();
ParcelUuid[] uuids = btDevice.getUuids(); //<-- this is always null!! :(
Log.d(TAG, ""+btDevice.fetchUuidsWithSdp()); //<-- prints true.
Log.d(TAG, "result : " + result.toString()); //<-- prints a bunch of relevant info that contains the UUID I want to check.
Log.d(TAG, "uuids : " + uuids); //<-- prints null.
/*
for (ParcelUuid u : uuids) {
//Compare with the UUID of my device, and connect if ok.
}
*/
}
然而,btDevice.getUuids(); 一直返回空值并且没有错误...
我如何获取已扫描设备的UUID?
一种暴力方法是使用regexp和result.toString()来获取我想要的内容,但一定会有更好的方法,不是吗?
谢谢。