当前位置: 首页 > 知识库问答 >
问题:

AltBeacon对Onyxbeacon不稳定,反复循环通过didEnterRegion和didExitRegion

柳德义
2023-03-14

我们还在不同的设备(三星手机)上使用不同的(Onyx)信标测试了这一点。问题仍然存在。请注意,这只发生在Onyx信标上(信标一)。万向节信标(系列21)在射程内仅触发一次。

我是否使用了正确的信标解析器字符串?我执行这个正确吗?我真的没有想法,我想支持这两个灯塔。

基应用程序

public class BaseApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        startService(new Intent(this, BeaconMonitoringService.class));
    }

}

信标监测服务

public class BeaconMonitoringService extends Service implements BeaconConsumer{

    private Context context;

    private BeaconService service;
    private BeaconManager beaconManager;
    private NotificationCompat.Builder notifBuilder;

    @Override
    public void onCreate(){
        super.onCreate();
        context = getBaseContext();
        beaconManager = BeaconManager.getInstanceForApplication(this);
        beaconManager.setBackgroundMode(true);

        beaconManager.setBackgroundScanPeriod(1100l);
        beaconManager.setBackgroundBetweenScanPeriod(15000l);

        String[] beaconParsers = new String[] { "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24", "m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25", "m:2-3=0203,i:14-19l,d:10-13,p:9-9" };

        for(String beacon : beaconParsers){
            Log.i("BeaconService","layout: "+beacon);
            beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(beacon));           
        }
        beaconManager.bind(this);
    }

    @Override
    public void onBeaconServiceConnect() {
        beaconManager.setMonitorNotifier(new MonitorNotifier() {

            private String log;

            @Override
            public void didEnterRegion(Region region) {
                Beacon beacon = service.getBeacon(region.getId1().toString(), region.getId2().toString(), region.getId3().toString());
                log = "I just saw a beacon for the first time! "+region.getId1()+" "+region.getId2()+" "+region.getId3();
                Log.i("BeaconService", log);   
                sendNotification(beacon);
            }

            @Override
            public void didExitRegion(Region region) {
                Beacon beacon = service.getBeacon(region.getId1().toString(), region.getId2().toString(), region.getId3().toString());
                log = "I no longer see a beacon";
                Log.i("BeaconService", log);
            }

            @Override
            public void didDetermineStateForRegion(int state, Region region) {

            }
        });

        List<BackendRegion> regionList = Util.getRegionList();  
        for(BackendRegion region : regionList){
            ArrayList<Beacon> beaconList = region.getBeacons();
            for(Beacon beacon : beaconList){
                try {
                    String beaconString = region.getUuid().toLowerCase() + " " + beacon.getMajor() + " " + beacon.getMinor();
                    service.addBeacon(beacon);
                    beaconManager.startMonitoringBeaconsInRegion(new Region(beacon.getIdentifier(), Identifier.parse(region.getUuid()),Identifier.parse(beacon.getMajor()),Identifier.parse(beacon.getMinor())));
                } catch (RemoteException e) {    }
            }
        }

    }


    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onDestroy(){
        beaconManager.unbind(this);
        super.onDestroy();
    }

    private void sendNotification(Beacon beacon, InteractiveImage interactiveImage) {
        this.notifBuilder =  new NotificationCompat.Builder(this)
                .setAutoCancel(true)
                .setContentTitle("Sample Beacon")
                .setContentText("A beacon was detected")
                .setSmallIcon(R.drawable.ic_launcher);

        Intent notifyIntent = new Intent(this, NotificationActivity.class);
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
        notifBuilder.setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(Integer.parseInt(beacon.getId()), notifBuilder.build());

    }

}

原木

12-11 15:45:24.103 I/BeaconService: I just saw a beacon for the first time! 20cae8a0-a9cf-11e3-a5e2-0800200c9a66 7 44512
12-11 15:45:24.784 D/BluetoothAdapter: stopLeScan()
12-11 15:45:39.698 D/BluetoothAdapter: startLeScan(): null
12-11 15:45:39.709 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:45:40.830 D/BluetoothAdapter: stopLeScan()
12-11 15:45:55.794 D/BluetoothAdapter: startLeScan(): null
12-11 15:45:55.804 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:45:56.985 D/BluetoothAdapter: stopLeScan()
12-11 15:46:11.920 D/BluetoothAdapter: startLeScan(): null
12-11 15:46:11.950 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:46:13.091 D/BluetoothAdapter: stopLeScan()
12-11 15:46:27.996 D/BluetoothAdapter: startLeScan(): null
12-11 15:46:28.016 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:46:29.147 D/BluetoothAdapter: stopLeScan()
12-11 15:46:29.227 I/BeaconService: I no longer see a beacon
12-11 15:46:44.121 D/BluetoothAdapter: startLeScan(): null
12-11 15:46:44.141 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:46:44.402 I/BeaconService: I just saw a beacon for the first time! 20cae8a0-a9cf-11e3-a5e2-0800200c9a66 7 44512
12-11 15:46:45.282 D/BluetoothAdapter: stopLeScan()
12-11 15:47:00.197 D/BluetoothAdapter: startLeScan(): null
12-11 15:47:00.197 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:47:01.328 D/BluetoothAdapter: stopLeScan()
12-11 15:47:16.343 D/BluetoothAdapter: startLeScan(): null
12-11 15:47:16.363 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:47:17.514 D/BluetoothAdapter: stopLeScan()
12-11 15:47:32.418 D/BluetoothAdapter: startLeScan(): null
12-11 15:47:32.428 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:47:33.540 D/BluetoothAdapter: stopLeScan()
12-11 15:47:48.494 D/BluetoothAdapter: startLeScan(): null
12-11 15:47:48.504 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:47:49.635 D/BluetoothAdapter: stopLeScan()
12-11 15:48:04.620 D/BluetoothAdapter: startLeScan(): null
12-11 15:48:04.630 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:48:05.771 D/BluetoothAdapter: stopLeScan()
12-11 15:48:20.706 D/BluetoothAdapter: startLeScan(): null
12-11 15:48:20.706 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:48:21.827 D/BluetoothAdapter: stopLeScan()
12-11 15:48:36.821 D/BluetoothAdapter: startLeScan(): null
12-11 15:48:36.831 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:48:37.962 D/BluetoothAdapter: stopLeScan()
12-11 15:48:52.917 D/BluetoothAdapter: startLeScan(): null
12-11 15:48:52.927 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:48:54.058 D/BluetoothAdapter: stopLeScan()
12-11 15:49:09.003 D/BluetoothAdapter: startLeScan(): null
12-11 15:49:09.003 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:49:10.154 D/BluetoothAdapter: stopLeScan()
12-11 15:49:10.214 I/BeaconService: I no longer see a beacon

共有1个答案

农存
2023-03-14

几个小贴士:

>

  • 检查Onyx Beacon One的广告率。为了获得最佳效果,信标应该以标准的10Hz进行广告。一些制造商放慢这一广告速度以节省电池寿命。如果你有一个信标是在1Hz或更少的频率广告,它可以开始被定期错过的信标扫描仪。(由于蓝牙无线电噪声,不是100%的数据包被检测到。)

    如果你发现广告率是1赫兹或更少,增加广告率,如果可能的话,这个问题应该会消失。

  •  类似资料:
    • 问题内容: 为了在用户单击“清除按钮”时初始化a上的所有,我需要遍历(而不是将所有单个字段都设置为“”)。 我如何使用for-each循环来遍历s的搜索? 问题答案: 但是,如果您具有更深层嵌套的JTextField,则可以使用以下递归形式: 编辑: Tom Hawtin的 一个样本 -粗线 建议将在您的框架班级中列出: 并在初始化单个文本字段时,将它们添加到此列表中: 当用户单击清除按钮时,只需

    • 我希望我的android应用程序执行一些代码,当它进入特定信标的指定范围(RaspberryPi与蓝牙加密狗)。 这是我在RPi上使用的开始发出的命令: 我已经编辑了BeaconLayout来检测iBeacons: 我假设这与覆盆子PI的传输速率有关,但我无法将其改变为有效的。

    • 问题内容: 为什么通过硒切换到警报不稳定? 例如。 1.运行代码,一切顺利。一切顺利。但是,如果这段代码在几分钟内运行,则可能会出现错误。例如,没有元素可以单击。等等。 2.在一个站点上,有一个警报窗口。 所以我关闭了。但是他一直在工作。一切都好,然后是错误。 我写了,一切都按预期进行。 但是我认为这并不漂亮。 为什么一切都这么不稳定? 非常感谢你。 问题答案: 根据您的代码块,您需要解决以下两个

    • 问题内容: 什么是执行以下操作的最佳方法: 但是,事情是我不想创建具有相同名称的对象,我想创建具有不同名称的对象,例如,我想将每个对象添加到列表中。做这个的最好方式是什么 ? 问题答案: 您无需为每个对象使用不同的名称。由于o1对象是在for循环中声明的,因此o1变量的范围仅限于for循环,并且在每次迭代过程中都会重新创建它…除非每次它将引用该迭代过程中创建的新对象。请注意,变量本身不存储在列表中

    • 如何通过XML实现这一点:使用特定的src创建,并使其带有边框?

    • 我希望得到像这里测试1-4这样的期望输出,并且仍然使用Scanner scan=new Scanner(System.in)提示用户输入测试。我的程序显示超出范围。我该怎么解决这个问题?