gpt4 book ai didi

Android 在 Linux 上找到使用 Bluez 创建的信标

转载 作者:太空宇宙 更新时间:2023-11-04 10:20:30 26 4
gpt4 key购买 nike

您好,我正在尝试将 Android 应用程序连接到我在 RaspberryPi 3 上使用 Bluez 5.23 创建的 Eddystone UID Beacon。

信标是使用以下命令创建的:

sudo hciconfig hci0 up
sudo hciconfig hci0 leadv 3
sudo hcitool -i hci0 cmd 0x08 0x0008 1F 02 01 06 03 03 AA FE 17 16 AA FE 00 E7 01 02 03 04 05 06 07 08 09 0A 01 02 03 04 05 06 00 00

这个信标显然工作正常,因为我可以在 Android 设备上使用像 Beacon Toy 这样的商店应用程序看到它。 .

我在主 Activity 中使用以下代码来发现信标:

public class MainActivity extends AppCompatActivity implements BeaconConsumer, MonitorNotifier {
...
@Override
public void onResume() {
super.onResume();
beaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext());
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
beaconManager.bind(this);
}

@Override
public void onBeaconServiceConnect() {
Region region = new Region("my-beacon-region", null, null, null);
beaconManager.addMonitorNotifier(this);
try {
beaconManager.startMonitoringBeaconsInRegion(region);
} catch (RemoteException e) {
e.printStackTrace();
}
}

public void didEnterRegion(Region region) {
Log.d(TAG, "I detected a beacon in the region with namespace id " + region.getId1() +
" and instance id: " + region.getId2());
}
}

有人知道会发生什么吗?永远不会调用方法 didEnterRegion。我还在类中放置了一个“didDetermineStateForRegion”方法,但我总是在状态参数中收到 OUTSIDE,这意味着我不在该地区。

最佳答案

我猜你没有请求或没有批准你的应用程序的蓝牙和位置权限。看:https://altbeacon.github.io/android-beacon-library/requesting_permission.html .

如果您已经拥有正确的权限,那么有几个问题可以确定:
Beacon Toy 应用程序是否将信标识别为 Eddystone UID
onBeaconServiceConnect 是否被调用?

一个小提示:我建议您在 onCreate 方法而不是 onResume 方法中初始化 BeaconManager。每当您的应用程序立即恢复时,您都会添加新的解析器。我实际上是在应用程序对象中执行此操作,因为甚至可以多次调用 Activity 的 onCreate。

关于Android 在 Linux 上找到使用 Bluez 创建的信标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44081946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com