Search in sources :

Example 1 with BluetoothCrashResolver

use of org.altbeacon.bluetooth.BluetoothCrashResolver in project android-beacon-library by AltBeacon.

the class BeaconService method onCreate.

@MainThread
@Override
public void onCreate() {
    this.startForegroundIfConfigured();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        bluetoothCrashResolver = new BluetoothCrashResolver(this);
        bluetoothCrashResolver.start();
    }
    mScanHelper = new ScanHelper(this);
    if (mScanHelper.getCycledScanner() == null) {
        mScanHelper.createCycledLeScanner(false, bluetoothCrashResolver);
    }
    mScanHelper.setMonitoringStatus(MonitoringStatus.getInstanceForApplication(this));
    mScanHelper.setRangedRegionState(new HashMap<Region, RangeState>());
    mScanHelper.setBeaconParsers(new HashSet<BeaconParser>());
    mScanHelper.setExtraDataBeaconTracker(new ExtraDataBeaconTracker());
    BeaconManager beaconManager = BeaconManager.getInstanceForApplication(getApplicationContext());
    beaconManager.setScannerInSameProcess(true);
    if (beaconManager.isMainProcess()) {
        LogManager.i(TAG, "beaconService version %s is starting up on the main process", BuildConfig.VERSION_NAME);
        // if we are on the main process, we use local broadcast notifications to deliver results.
        ensureNotificationProcessorSetup();
    } else {
        LogManager.i(TAG, "beaconService version %s is starting up on a separate process", BuildConfig.VERSION_NAME);
        ProcessUtils processUtils = new ProcessUtils(this);
        LogManager.i(TAG, "beaconService PID is " + processUtils.getPid() + " with process name " + processUtils.getProcessName());
    }
    String longScanForcingEnabled = getManifestMetadataValue("longScanForcingEnabled");
    if (longScanForcingEnabled != null && longScanForcingEnabled.equals("true")) {
        LogManager.i(TAG, "longScanForcingEnabled to keep scans going on Android N for > 30 minutes");
        if (mScanHelper.getCycledScanner() != null) {
            mScanHelper.getCycledScanner().setLongScanForcingEnabled(true);
        }
    }
    mScanHelper.reloadParsers();
    DistanceCalculator defaultDistanceCalculator = new ModelSpecificDistanceCalculator(this, BeaconManager.getDistanceModelUpdateUrl());
    Beacon.setDistanceCalculator(defaultDistanceCalculator);
    // Look for simulated scan data
    try {
        Class klass = Class.forName("org.altbeacon.beacon.SimulatedScanData");
        java.lang.reflect.Field f = klass.getField("beacons");
        mScanHelper.setSimulatedScanData((List<Beacon>) f.get(null));
    } catch (ClassNotFoundException e) {
        LogManager.d(TAG, "No org.altbeacon.beacon.SimulatedScanData class exists.");
    } catch (Exception e) {
        LogManager.e(e, TAG, "Cannot get simulated Scan data.  Make sure your org.altbeacon.beacon.SimulatedScanData class defines a field with the signature 'public static List<Beacon> beacons'");
    }
}
Also used : DistanceCalculator(org.altbeacon.beacon.distance.DistanceCalculator) ModelSpecificDistanceCalculator(org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator) BluetoothCrashResolver(org.altbeacon.bluetooth.BluetoothCrashResolver) ProcessUtils(org.altbeacon.beacon.utils.ProcessUtils) BeaconParser(org.altbeacon.beacon.BeaconParser) BeaconManager(org.altbeacon.beacon.BeaconManager) Beacon(org.altbeacon.beacon.Beacon) Region(org.altbeacon.beacon.Region) ModelSpecificDistanceCalculator(org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator) MainThread(androidx.annotation.MainThread)

Aggregations

MainThread (androidx.annotation.MainThread)1 Beacon (org.altbeacon.beacon.Beacon)1 BeaconManager (org.altbeacon.beacon.BeaconManager)1 BeaconParser (org.altbeacon.beacon.BeaconParser)1 Region (org.altbeacon.beacon.Region)1 DistanceCalculator (org.altbeacon.beacon.distance.DistanceCalculator)1 ModelSpecificDistanceCalculator (org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator)1 ProcessUtils (org.altbeacon.beacon.utils.ProcessUtils)1 BluetoothCrashResolver (org.altbeacon.bluetooth.BluetoothCrashResolver)1