use of org.altbeacon.beacon.distance.DistanceCalculator 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'");
}
}
Aggregations