• 13
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Only for the first time lauching the app (after uninstall/install), after it starts scanning beacons, the message "App isn't responding" appears, only happening on Android 8 (Samsung A5 and J5 Prime). Removed everything from app leaving only the code for beacon detection, still happening. Not sure if it's a problem with the library or the way I'm using it.

Calling BeaconConsumer(context) from my Application class.

public class BeaconConsumer implements BootstrapNotifier, org.altbeacon.beacon.BeaconConsumer {
    BeaconManager beaconManager;
    BeaconConsumer(Context applicationContext) {
        beaconManager = BeaconManager.getInstanceForApplication(applicationContext);
        beaconManager.getBeaconParsers().clear();
        beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=6548,i:4-25,p:1-1"));
        beaconManager.setEnableScheduledScanJobs(false);
        beaconManager.setBackgroundBetweenScanPeriod(15300);
        beaconManager.setBackgroundScanPeriod(1200);
        beaconManager.setForegroundBetweenScanPeriod(10000);
        beaconManager.setForegroundScanPeriod(1200);
        beaconManager.bind(this);           
        beaconManager.setBackgroundMode(false);
        BeaconManager.setDebug(true);
        Region region = new Region("backgroundRegion", null, null, null);
        RegionBootstrap regionBootstrap = new RegionBootstrap(this, region);
    }

    public void onBeaconServiceConnect() {
        beaconManager.removeAllRangeNotifiers();
        beaconManager.addRangeNotifier((beacons, region) -> {
            Log.d("TAG", "didRangeBeaconsInRegion CALLED with size: " + beacons.size() + " on region: " + region);
            Iterator<Beacon> iterator = beacons.iterator();
            while (iterator.hasNext()) {
                Beacon beacon = iterator.next();
                Formatter formatter = new Formatter();
                for (byte b : beacon.getId1().toByteArray()) {
                    formatter.format("%02x", b);
                }
                String payload = formatter.toString();
                Log.d("TAG", "Processing payload: " + payload + " rssi: " + beacon.getRssi());
            }
        });

        try {
            beaconManager.startRangingBeaconsInRegion(myRegion);
        } catch (RemoteException e) {
            Log.d("TAG", "Exception starting ranging beacons in region");
        }
    }

    public void didEnterRegion(Region region) {
        try {
            beaconManager.startRangingBeaconsInRegion(region);
        } catch (RemoteException e) {
            Log.d("TAG", "Can't start ranging");
        }

        Intent intent = new Intent(mContext, BeaconService.class);
        intent.setAction("com.test.altbeacontest.beaconreference.Service.action.Scan");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            mContext.startForegroundService(intent);
        } else {
            mContext.startService(intent);
        }
        mConnection = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                Log.d("TAG", "ServiceConnection - connected");
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                Log.d("TAG", "ServiceConnection - disconnected");
            }
        };
        bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    }

    public void didExitRegion(Region region) {
        Log.d("TAG", "I no longer see a beacon.");
        insideRegion = false;

        try {
            beaconManager.stopRangingBeaconsInRegion(region);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}

I suspect the problem has something to do with these operations used together in the same method:

beaconManager.bind(this);           
...
RegionBootstrap regionBootstrap = new RegionBootstrap(this, region);

You really should not use these two together -- generally you use one or the other (binding to the BeaconManager) or using RegionBootstrap. The latter object itself binds internally.

I would remove: RegionBootstrap regionBootstrap = new RegionBootstrap(this, region); and instead add beaconManager.startMonitoringBeaconsInRegion(region); at the same time as you call beaconManager.startRangingBeaconsInRegion(myRegion);

  • 1
Reply Report