简体   繁体   English

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

[英]Android find a beacon created using Bluez on Linux

Hi I'm trying to connect an Android app to an Eddystone UID Beacon I've created using Bluez 5.23 at a RaspberryPi 3. 嗨,我正尝试将Android应用程序连接到我在RaspberryPi 3上使用Bluez 5.23创建的Eddystone UID Beacon。

The beacon was created using the following command: 使用以下命令创建信标:

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

This beacon is apparently working properly cause I can see it in an Android device using some store app like Beacon Toy . 这个信标显然工作正常,因为我可以在Android设备上使用诸如Beacon Toy之类的商店应用程序看到它。

I am using the following code inside the Main Activity in order to discover the beacon: 我在“主要活动”中使用以下代码以发现信标:

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());
}
}

Anyone knows what might be happening? 有人知道会发生什么吗? The method didEnterRegion is never called. 永远不会调用didEnterRegion方法。 I also put a 'didDetermineStateForRegion' method inside the class but I always receive OUTSIDE in the state param meaning that I'm not in the region. 我还在类中放置了一个'didDetermineStateForRegion'方法,但是我总是在状态参数中收到OUTSIDE ,这意味着我不在该区域中。

I guess you did not request or did not approve the Bluetooth and Location permissions for your application. 我猜您没有请求或未批准您的应用程序的蓝牙和位置权限。 Look at: https://altbeacon.github.io/android-beacon-library/requesting_permission.html . 查看: https : //altbeacon.github.io/android-beacon-library/requesting_permission.html

If you have the correct permissions already then few questions to be sure: 如果您已经具有正确的权限,那么可以确定以下几个问题:
Is the beacon recognized as Eddystone UID by the Beacon Toy app? 信标玩具应用程序将信标识别Eddystone UID吗?
Is onBeaconServiceConnect called? 是否调用了onBeaconServiceConnect?

A small hint: I recommend you to initialize the BeaconManager in onCreate method instead of onResume. 一个小提示:我建议您使用onCreate方法而不是onResume初始化BeaconManager。 You are adding new parser whenever your app is resumed right now. 每当您的应用立即恢复时,您都将添加新的解析器。 I am actually doing this in application object as even onCreate of activity can be called multiple times. 我实际上是在应用程序对象中执行此操作,因为活动的onCreate可以多次调用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM