org.altbeacon.beacon.BeaconParser Java Examples

The following examples show how to use org.altbeacon.beacon.BeaconParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeaconSimulatorFragment.java    From iBeacon-Android with Apache License 2.0 6 votes vote down vote up
private void setupBeacon() {
    beacon = new Beacon.Builder()
            .setId1(getString(R.string.beacon_uuid_simulator)) // UUID for beacon
            .setId2(getString(R.string.beacon_major_simulator)) // Major for beacon
            .setId3(getString(R.string.beacon_minor_simulator)) // Minor for beacon
            .setManufacturer(0x004C) // Radius Networks.0x0118  Change this for other beacon layouts//0x004C for iPhone
            .setTxPower(-56) // Power in dB
            .setDataFields(Arrays.asList(new Long[]{0l})) // Remove this for beacon layouts without d: fields
            .build();

    btManager = (BluetoothManager) getActivity().getSystemService (Context.BLUETOOTH_SERVICE);
    btAdapter = btManager.getAdapter ();

    beaconTransmitter = new BeaconTransmitter (getActivity(), new BeaconParser()
            .setBeaconLayout ("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
}
 
Example #2
Source File: EddystoneTelemetryAccessor.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the raw Eddystone telemetry bytes from the extra data fields of an associated beacon.
 * This is useful for passing the telemetry to Google's backend services.
 * @param beacon
 * @return the bytes of the telemetry frame
 */
public byte[] getTelemetryBytes(Beacon beacon) {
    if (beacon.getExtraDataFields().size() >= 5) {
        Beacon telemetryBeacon = new Beacon.Builder()
                .setDataFields(beacon.getExtraDataFields())
                .build();
        BeaconParser telemetryParser = new BeaconParser()
                .setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT);
        byte[] telemetryBytes = telemetryParser.getBeaconAdvertisementData(telemetryBeacon);
        Log.d(TAG, "Rehydrated telemetry bytes are :" + byteArrayToString(telemetryBytes));
        return telemetryBytes;
    }
    else {
        return null;
    }
}
 
Example #3
Source File: BleManager.java    From thunderboard-android with Apache License 2.0 6 votes vote down vote up
@Inject
public BleManager(@ForApplication Context context, PreferenceManager prefsManager) {
    this.context = context;

    // the app manifest requires support for BLE, no need to check explicitly
    bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
    bluetoothAdapter = bluetoothManager.getAdapter();
    preferenceManager = prefsManager;
    gattManager = new GattManager(prefsManager, this);

    // Beaconing
    beaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(context);
    beaconManager.getBeaconParsers().clear();
    beaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));

    Timber.d("setting up background monitoring for beacons and power saving");
    Identifier id1 = Identifier.parse(ThunderBoardDevice.THUNDER_BOARD_REACT_UUID_STRING);
    Region region = new Region("backgroundRegion", id1, null, null);
    regionBootstrap = new ThunderBoardBootstrap(context, this, region);
    backgroundPowerSaver = new ThunderBoardPowerSaver(context, preferenceManager);

    beaconManager.setBackgroundBetweenScanPeriod(ThunderBoardPowerSaver.DELAY_BETWEEN_SCANS_INACTIVE);

    handler = new Handler();
}
 
Example #4
Source File: Application.java    From PresencePublisher with MIT License 6 votes vote down vote up
private void initBeaconReceiver() {
    if (supportsBeacons()) {
        LogManager.setLogger(new HyperlogLogger());
        Beacon.setHardwareEqualityEnforced(true);
        Beacon.setDistanceCalculator(new ModelSpecificDistanceCalculator(this, org.altbeacon.beacon.BeaconManager.getDistanceModelUpdateUrl()));
        org.altbeacon.beacon.BeaconManager beaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);
        List<BeaconParser> beaconParsers = beaconManager.getBeaconParsers();
        beaconParsers.add(new BeaconParser("iBeacon")
                .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
        beaconParsers.add(new BeaconParser("Eddystone UID")
                .setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));

        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        if (!sharedPreferences.getStringSet(BEACON_LIST, Collections.emptySet()).isEmpty()) {
            BeaconManager.getInstance().initialize(this);
        }
        if (Build.VERSION.SDK_INT >= 18) {
            backgroundPowerSaver = new BackgroundPowerSaver(this);
        }
    }
}
 
Example #5
Source File: BeaconLocatorApp.java    From beaconloc with Apache License 2.0 5 votes vote down vote up
private void initBeaconManager() {

        if (PreferencesUtil.isEddystoneLayoutUID(this)) {
            mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
        }
        if (PreferencesUtil.isEddystoneLayoutURL(this)) {
            mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT));
        }
        if (PreferencesUtil.isEddystoneLayoutTLM(this)) {
            mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT));
        }
        mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.ALTBEACON_LAYOUT));


        //konkakt?
        mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
        mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
        mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));

        mBeaconManager.setAndroidLScanningDisabled(true);
        mBeaconManager.setBackgroundScanPeriod(15000L);
        mBeaconManager.setForegroundBetweenScanPeriod(0L);      // default is 0L
        mBeaconManager.setForegroundScanPeriod(1100L);          // Default is 1100L

        mBackgroundSwitchWatcher = new BackgroundSwitchWatcher(this);

        if (PreferencesUtil.isForegroundScan(this) && PreferencesUtil.isBackgroundScan(this)) {

            startScanAsForegroundService();

        } else {

            stopScanAsForegroundService();
        }

        enableBackgroundScan(true);

    }
 
Example #6
Source File: ScanFilterUtilsTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void testZeroOffsetScanFilter() throws Exception {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    BeaconParser parser = new BeaconParser();
    parser.setBeaconLayout("m:0-3=11223344,i:4-6,p:24-24");
    BeaconManager.setsManifestCheckingDisabled(true); // no manifest available in robolectric
    List<ScanFilterUtils.ScanFilterData> scanFilterDatas = new ScanFilterUtils().createScanFilterDataForBeaconParser(parser);
    assertEquals("scanFilters should be of correct size", 1, scanFilterDatas.size());
    ScanFilterUtils.ScanFilterData sfd = scanFilterDatas.get(0);
    assertEquals("manufacturer should be right", 0x004c, sfd.manufacturer);
    assertEquals("mask length should be right", 2, sfd.mask.length);
    assertArrayEquals("mask should be right", new byte[] {(byte)0xff, (byte)0xff}, sfd.mask);
    assertArrayEquals("filter should be right", new byte[] {(byte)0x33, (byte)0x44}, sfd.filter);
}
 
Example #7
Source File: ScanFilterUtilsTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void testEddystoneScanFilterData() throws Exception {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    BeaconParser parser = new BeaconParser();
    parser.setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT);
    BeaconManager.setsManifestCheckingDisabled(true); // no manifest available in robolectric
    List<ScanFilterUtils.ScanFilterData> scanFilterDatas = new ScanFilterUtils().createScanFilterDataForBeaconParser(parser);
    assertEquals("scanFilters should be of correct size", 1, scanFilterDatas.size());
    ScanFilterUtils.ScanFilterData sfd = scanFilterDatas.get(0);
    assertEquals("serviceUuid should be right", new Long(0xfeaa), sfd.serviceUuid);
}
 
Example #8
Source File: ScanFilterUtilsTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericScanFilter() throws Exception {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    BeaconParser parser = new BeaconParser();
    parser.setBeaconLayout("m:2-3=1111,i:4-6,p:24-24");
    BeaconManager.setsManifestCheckingDisabled(true); // no manifest available in robolectric
    List<ScanFilterUtils.ScanFilterData> scanFilterDatas = new ScanFilterUtils().createScanFilterDataForBeaconParser(parser);
    assertEquals("scanFilters should be of correct size", 1, scanFilterDatas.size());
    ScanFilterUtils.ScanFilterData sfd = scanFilterDatas.get(0);
    assertEquals("manufacturer should be right", 0x004c, sfd.manufacturer);
    assertEquals("mask length should be right", 2, sfd.mask.length);
    assertArrayEquals("mask should be right", new byte[]{(byte) 0xff, (byte) 0xff}, sfd.mask);
    assertArrayEquals("filter should be right", new byte[] {(byte)0x11, (byte) 0x11}, sfd.filter);
    assertNull("serviceUuid should be null", sfd.serviceUuid);
}
 
Example #9
Source File: ScanFilterUtilsTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAltBeaconScanFilter() throws Exception {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    BeaconParser parser = new AltBeaconParser();
    BeaconManager.setsManifestCheckingDisabled(true); // no manifest available in robolectric
    List<ScanFilterUtils.ScanFilterData> scanFilterDatas = new ScanFilterUtils().createScanFilterDataForBeaconParser(parser);
    assertEquals("scanFilters should be of correct size", 1, scanFilterDatas.size());
    ScanFilterUtils.ScanFilterData sfd = scanFilterDatas.get(0);
    assertEquals("manufacturer should be right", 0x0118, sfd.manufacturer);
    assertEquals("mask length should be right", 2, sfd.mask.length);
    assertArrayEquals("mask should be right", new byte[] {(byte)0xff, (byte)0xff}, sfd.mask);
    assertArrayEquals("filter should be right", new byte[] {(byte)0xbe, (byte)0xac}, sfd.filter);
}
 
Example #10
Source File: ScanFilterUtils.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
public List<ScanFilter> createScanFiltersForBeaconParsers(List<BeaconParser> beaconParsers) {
    List<ScanFilter> scanFilters = new ArrayList<ScanFilter>();
    // for each beacon parser, make a filter expression that includes all its desired
    // hardware manufacturers
    for (BeaconParser beaconParser: beaconParsers) {
        List<ScanFilterData> sfds = createScanFilterDataForBeaconParser(beaconParser);
        for (ScanFilterData sfd: sfds) {
            ScanFilter.Builder builder = new ScanFilter.Builder();
            if (sfd.serviceUuid != null) {
                // Use a 16 bit service UUID in a 128 bit form
                String serviceUuidString = String.format("0000%04X-0000-1000-8000-00805f9b34fb", sfd.serviceUuid);
                String serviceUuidMaskString = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
                ParcelUuid parcelUuid = ParcelUuid.fromString(serviceUuidString);
                ParcelUuid parcelUuidMask = ParcelUuid.fromString(serviceUuidMaskString);
                if (LogManager.isVerboseLoggingEnabled()) {
                    LogManager.d(TAG, "making scan filter for service: "+serviceUuidString+" "+parcelUuid);
                    LogManager.d(TAG, "making scan filter with service mask: "+serviceUuidMaskString+" "+parcelUuidMask);
                }
                builder.setServiceUuid(parcelUuid, parcelUuidMask);
            }
            else {
                builder.setServiceUuid(null);
                builder.setManufacturerData((int) sfd.manufacturer, sfd.filter, sfd.mask);
            }
            ScanFilter scanFilter = builder.build();
            if (LogManager.isVerboseLoggingEnabled()) {
                LogManager.d(TAG, "Set up a scan filter: "+scanFilter);
            }
            scanFilters.add(scanFilter);
        }
    }
    return scanFilters;
}
 
Example #11
Source File: ScanFilterUtils.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
public List<ScanFilterData> createScanFilterDataForBeaconParser(BeaconParser beaconParser) {
    ArrayList<ScanFilterData> scanFilters = new ArrayList<ScanFilterData>();
    for (int manufacturer : beaconParser.getHardwareAssistManufacturers()) {
        Long serviceUuid = beaconParser.getServiceUuid();
        long typeCode = beaconParser.getMatchingBeaconTypeCode();
        int startOffset = beaconParser.getMatchingBeaconTypeCodeStartOffset();
        int endOffset = beaconParser.getMatchingBeaconTypeCodeEndOffset();

        // Note: the -2 here is because we want the filter and mask to start after the
        // two-byte manufacturer code, and the beacon parser expression is based on offsets
        // from the start of the two byte code
        int length = endOffset + 1 - 2;
        byte[] filter = new byte[0];
        byte[] mask = new byte[0];
        if (length > 0) {
            filter = new byte[length];
            mask = new byte[length];
            byte[] typeCodeBytes = BeaconParser.longToByteArray(typeCode, endOffset-startOffset+1);
            for (int layoutIndex = 2; layoutIndex <= endOffset; layoutIndex++) {
                int filterIndex = layoutIndex-2;
                if (layoutIndex < startOffset) {
                    filter[filterIndex] = 0;
                    mask[filterIndex] = 0;
                } else {
                    filter[filterIndex] = typeCodeBytes[layoutIndex-startOffset];
                    mask[filterIndex] = (byte) 0xff;
                }
            }
        }

        ScanFilterData sfd = new ScanFilterData();
        sfd.manufacturer = manufacturer;
        sfd.filter = filter;
        sfd.mask = mask;
        sfd.serviceUuid = serviceUuid;
        scanFilters.add(sfd);

    }
    return scanFilters;
}
 
Example #12
Source File: ScanHelper.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@WorkerThread
@Override
protected Void doInBackground(ScanHelper.ScanData... params) {
    ScanHelper.ScanData scanData = params[0];
    Beacon beacon = null;

    for (BeaconParser parser : ScanHelper.this.mBeaconParsers) {
        beacon = parser.fromScanData(scanData.scanRecord, scanData.rssi, scanData.device, scanData.timestampMs);

        if (beacon != null) {
            break;
        }
    }
    if (beacon != null) {
        if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG, "Beacon packet detected for: "+beacon+" with rssi "+beacon.getRssi());
        }
        mDetectionTracker.recordDetection();
        if (mCycledScanner != null && !mCycledScanner.getDistinctPacketsDetectedPerScan()) {
            if (!mDistinctPacketDetector.isPacketDistinct(scanData.device.getAddress(),
                    scanData.scanRecord)) {
                LogManager.i(TAG, "Non-distinct packets detected in a single scan.  Restarting scans unecessary.");
                mCycledScanner.setDistinctPacketsDetectedPerScan(true);
            }
        }
        processBeaconFromScan(beacon);
    } else {
        if (mNonBeaconLeScanCallback != null) {
            mNonBeaconLeScanCallback.onNonBeaconLeScan(scanData.device, scanData.rssi, scanData.scanRecord);
        }
    }
    return null;
}
 
Example #13
Source File: ScanHelper.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
void reloadParsers() {
    HashSet<BeaconParser> newBeaconParsers = new HashSet<>();
    //flatMap all beacon parsers
    boolean matchBeaconsByServiceUUID = true;
    newBeaconParsers.addAll(mBeaconManager.getBeaconParsers());
    for (BeaconParser beaconParser : mBeaconManager.getBeaconParsers()) {
        if (beaconParser.getExtraDataParsers().size() > 0) {
            matchBeaconsByServiceUUID = false;
            newBeaconParsers.addAll(beaconParser.getExtraDataParsers());
        }
    }
    mBeaconParsers = newBeaconParsers;
    //initialize the extra data beacon tracker
    mExtraDataBeaconTracker = new ExtraDataBeaconTracker(matchBeaconsByServiceUUID);
}
 
Example #14
Source File: BeaconService.java    From BeaconControl_Android_SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    config = ConfigImpl.getInstance(getApplicationContext());

    beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(config.getBeaconParserLayout()));
    beaconManager.bind(this);

    clientsManager = new ClientsManager(this, beaconManager);
}
 
Example #15
Source File: MainActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMainTv = (TextView) findViewById(R.id.main_tv);

    beaconManager = BeaconManager.getInstanceForApplication(this);
    // To detect proprietary beacons, you must add a line like below corresponding to your beacon
    // type.  Do a web search for "setBeaconLayout" to get the proper expression.
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager.bind(this);
}
 
Example #16
Source File: BeaconScannerFragment.java    From iBeacon-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    beaconManager = BeaconManager.getInstanceForApplication(getActivity());

    beaconManager.getBeaconParsers().add(new BeaconParser()
            .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

    RxPermissions.getInstance(getContext())
            .request(Manifest.permission.ACCESS_COARSE_LOCATION)
            .subscribe(new Observer<Boolean>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(Boolean granted) {
                    checkinBtn.setEnabled(true);
                }
            });


}
 
Example #17
Source File: BeaconBroadcast.java    From react-native-ibeacon-simulator with MIT License 5 votes vote down vote up
@ReactMethod
public void startSharedAdvertisingBeaconWithString(String uuid, int major, int minor,String identifier) {
int manufacturer = 0x4C;
Beacon beacon = new Beacon.Builder()
		.setId1(uuid)
		.setId2(String.valueOf(major))
		.setId3(String.valueOf(minor))
		.setManufacturer(manufacturer)
		.setBluetoothName(identifier)
		.setTxPower(-59)
		.build();
BeaconParser beaconParser = new BeaconParser()
		.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
this.beaconTransmitter = new BeaconTransmitter(context, beaconParser);
this.beaconTransmitter.startAdvertising(beacon, new AdvertiseCallback() {

	@Override
	public void onStartFailure(int errorCode) {
		Log.d("ReactNative", "Error from start advertising " + errorCode);
	}

	@Override
	public void onStartSuccess(AdvertiseSettings settingsInEffect) {
		Log.d("ReactNative", "Success start advertising");
	}
});
}
 
Example #18
Source File: Utils.java    From com.ruuvi.station with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void setAltBeaconParsers(BeaconManager beaconManager) {
    beaconManager.getBeaconParsers().clear();

    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(Constants.RuuviV2and4_LAYOUT));

    BeaconParser v3Parser = new BeaconParser().setBeaconLayout(Constants.RuuviV3_LAYOUT);
    v3Parser.setHardwareAssistManufacturerCodes(new int[]{1177});
    beaconManager.getBeaconParsers().add(v3Parser);

    BeaconParser v5Parser = new BeaconParser().setBeaconLayout(Constants.RuuviV5_LAYOUT);
    v5Parser.setHardwareAssistManufacturerCodes(new int[]{1177});
    beaconManager.getBeaconParsers().add(v5Parser);
}
 
Example #19
Source File: RxBeacon.java    From RxBeacon with Apache License 2.0 5 votes vote down vote up
public RxBeacon addBeaconParser(String parser) {
    beaconManager.getBeaconParsers()
            .add(new BeaconParser().
                    setBeaconLayout(parser));

    return this;
}
 
Example #20
Source File: BeaconScanDialogFragment.java    From PresencePublisher with MIT License 5 votes vote down vote up
@Override
public void onLeScan(BluetoothDevice bluetoothDevice, int rssi, byte[] scanRecord) {
    Beacon beacon = null;
    for (BeaconParser parser : beaconParsers) {
        beacon = parser.fromScanData(scanRecord, rssi, bluetoothDevice);
        if (beacon != null) {
            break;
        }
    }
    if (beacon != null && beacon.getBluetoothName() != null && beacon.getBluetoothAddress() != null) {
        adapter.addBeacon(beacon);
    }
}
 
Example #21
Source File: BeaconsAndroidModule.java    From react-native-beacons-android with MIT License 4 votes vote down vote up
@ReactMethod
public void removeParser(String parser) {
    mBeaconManager.getBeaconParsers().remove(new BeaconParser().setBeaconLayout(parser));
}
 
Example #22
Source File: ScanHelper.java    From android-beacon-library with Apache License 2.0 4 votes vote down vote up
void setBeaconParsers(Set<BeaconParser> beaconParsers) {
    mBeaconParsers = beaconParsers;
}
 
Example #23
Source File: BeaconsAndroidModule.java    From react-native-beacons-android with MIT License 4 votes vote down vote up
@ReactMethod
public void addParser(String parser) {
    mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(parser));
}
 
Example #24
Source File: ScanState.java    From android-beacon-library with Apache License 2.0 4 votes vote down vote up
public Set<BeaconParser> getBeaconParsers() {
    return mBeaconParsers;
}
 
Example #25
Source File: ScanState.java    From android-beacon-library with Apache License 2.0 4 votes vote down vote up
public void setBeaconParsers(Set<BeaconParser> beaconParsers) {
    mBeaconParsers = beaconParsers;
}
 
Example #26
Source File: SettingsData.java    From android-beacon-library with Apache License 2.0 4 votes vote down vote up
public void apply(@NonNull BeaconService scanService) {
    LogManager.d(TAG, "Applying settings changes to scanner in other process");
    BeaconManager beaconManager = BeaconManager.getInstanceForApplication(scanService);
    List<BeaconParser> beaconParsers = beaconManager.getBeaconParsers();
    boolean beaconParsersChanged = false;
    if (beaconParsers.size() == mBeaconParsers.size()) {
        for (int i = 0; i < beaconParsers.size(); i++) {
            if (!beaconParsers.get(i).equals(mBeaconParsers.get(i))) {
                LogManager.d(TAG, "Beacon parsers have changed to: "+mBeaconParsers.get(i).getLayout());
                beaconParsersChanged = true;
                break;
            }
        }
    }
    else {
        beaconParsersChanged = true;
        LogManager.d(TAG, "Beacon parsers have been added or removed.");
    }
    if (beaconParsersChanged) {
        LogManager.d(TAG, "Updating beacon parsers");
        beaconManager.getBeaconParsers().clear();
        beaconManager.getBeaconParsers().addAll(mBeaconParsers);
        scanService.reloadParsers();
    }
    else {
        LogManager.d(TAG, "Beacon parsers unchanged.");
    }
    MonitoringStatus monitoringStatus = MonitoringStatus.getInstanceForApplication(scanService);
    if (monitoringStatus.isStatePreservationOn() &&
            !mRegionStatePersistenceEnabled) {
        monitoringStatus.stopStatusPreservation();
    }
    else if (!monitoringStatus.isStatePreservationOn() &&
            mRegionStatePersistenceEnabled) {
        monitoringStatus.startStatusPreservation();
    }
    beaconManager.setAndroidLScanningDisabled(mAndroidLScanningDisabled);
    BeaconManager.setRegionExitPeriod(mRegionExitPeriod);
    RangeState.setUseTrackingCache(mUseTrackingCache);
    Beacon.setHardwareEqualityEnforced(mHardwareEqualityEnforced);
}
 
Example #27
Source File: BeaconScanDialogFragment.java    From PresencePublisher with MIT License 4 votes vote down vote up
public void setBeaconParsers(List<BeaconParser> beaconParsers) {
    this.beaconParsers = beaconParsers;
}