org.altbeacon.beacon.BeaconManager Java Examples

The following examples show how to use org.altbeacon.beacon.BeaconManager. 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: AltBeaconScannerForegroundService.java    From com.ruuvi.station with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "Starting foreground service");
    beaconManager = BeaconManager.getInstanceForApplication(getApplicationContext());
    Utils.setAltBeaconParsers(beaconManager);
    beaconManager.setBackgroundScanPeriod(5000);

    Foreground.init(getApplication());
    Foreground.get().addListener(listener);

    ruuviRangeNotifier = new RuuviRangeNotifier(getApplicationContext(), "AltBeaconFGScannerService");
    region = new Region("com.ruuvi.station.leRegion", null, null, null);
    startFG();
    beaconManager.bind(this);
    medic = RuuviScannerApplication.setupMedic(getApplicationContext());
    setBackground(); // start in background mode
}
 
Example #2
Source File: RegionBootstrap.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor to bootstrap your Application on an entry/exit from multiple regions
 *
 * @param application
 * @param regions
 */
public RegionBootstrap(BootstrapNotifier application, List<Region> regions) {
    if (application.getApplicationContext() == null) {
        throw new NullPointerException("The BootstrapNotifier instance is returning null from its getApplicationContext() method.  Have you implemented this method?");
    }

    this.context = application.getApplicationContext();
    this.regions = regions;
    this.monitorNotifier = application;
    beaconManager = BeaconManager.getInstanceForApplication(context);
    beaconConsumer = new InternalBeaconConsumer();
    if (beaconManager.isBackgroundModeUninitialized()) {
        beaconManager.setBackgroundMode(true);
    }
    beaconManager.bind(beaconConsumer);
    LogManager.d(TAG, "Waiting for BeaconService connection");
}
 
Example #3
Source File: RegionBootstrap.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor to bootstrap your Application on an entry/exit from a single region.
 *
 * @param application
 * @param region
 */
public RegionBootstrap(BootstrapNotifier application, Region region) {
    if (application.getApplicationContext() == null) {
        throw new NullPointerException("The BootstrapNotifier instance is returning null from its getApplicationContext() method.  Have you implemented this method?");
    }
    this.context = application.getApplicationContext();
    regions = new ArrayList<Region>();
    regions.add(region);
    this.monitorNotifier = application;
    beaconManager = BeaconManager.getInstanceForApplication(context);
    beaconConsumer = new InternalBeaconConsumer();
    if (beaconManager.isBackgroundModeUninitialized()) {
        beaconManager.setBackgroundMode(true);
    }
    beaconManager.bind(beaconConsumer);
    LogManager.d(TAG, "Waiting for BeaconService connection");
}
 
Example #4
Source File: RegionBootstrap.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor to bootstrap your Application on an entry/exit from multiple regions
 *
 * @param context
 * @param monitorNotifier
 * @param regions
 */
public RegionBootstrap(final Context context, final MonitorNotifier monitorNotifier, List<Region> regions) {
    if (context == null) {
        throw new NullPointerException("Application Context should not be null");
    }
    this.context = context.getApplicationContext();
    this.monitorNotifier = monitorNotifier;

    this.regions = regions;

    beaconManager = BeaconManager.getInstanceForApplication(context);
    beaconConsumer = new InternalBeaconConsumer();
    if (beaconManager.isBackgroundModeUninitialized()) {
        beaconManager.setBackgroundMode(true);
    }
    beaconManager.bind(beaconConsumer);
    LogManager.d(TAG, "Waiting for BeaconService connection");
}
 
Example #5
Source File: RegionBootstrap.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor to bootstrap your Application on an entry/exit from a single region.
 *
 * @param context
 * @param monitorNotifier
 * @param region
 */
public RegionBootstrap(final Context context, final MonitorNotifier monitorNotifier, Region region) {
    if (context == null) {
        throw new NullPointerException("Application Context should not be null");
    }
    this.context = context.getApplicationContext();
    this.monitorNotifier = monitorNotifier;
    regions = new ArrayList<Region>();
    regions.add(region);

    beaconManager = BeaconManager.getInstanceForApplication(context);
    beaconConsumer = new InternalBeaconConsumer();
    if (beaconManager.isBackgroundModeUninitialized()) {
        beaconManager.setBackgroundMode(true);
    }
    beaconManager.bind(beaconConsumer);
    LogManager.d(TAG, "Waiting for BeaconService connection");
}
 
Example #6
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 #7
Source File: ThunderBoardPowerSaver.java    From thunderboard-android with Apache License 2.0 6 votes vote down vote up
public ThunderBoardPowerSaver(Context context, PreferenceManager preferenceManager) {

        if (android.os.Build.VERSION.SDK_INT < 18) {
            Timber.d("BackgroundPowerSaver requires API 18 or higher.");
            return;
        }

        if (context instanceof Application) {
            ((Application) context).registerActivityLifecycleCallbacks(this);
        } else {
            Timber.e("Context is not an application instance, so we cannot use the BackgroundPowerSaver");
        }

        this.preferenceManager = preferenceManager;
        this.beaconManager = BeaconManager.getInstanceForApplication(context);
    }
 
Example #8
Source File: ScanState.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
public void applyChanges(BeaconManager beaconManager) {
    mBeaconParsers = new HashSet<>(beaconManager.getBeaconParsers());
    mForegroundScanPeriod = beaconManager.getForegroundScanPeriod();
    mForegroundBetweenScanPeriod = beaconManager.getForegroundBetweenScanPeriod();
    mBackgroundScanPeriod = beaconManager.getBackgroundScanPeriod();
    mBackgroundBetweenScanPeriod = beaconManager.getBackgroundBetweenScanPeriod();
    mBackgroundMode = beaconManager.getBackgroundMode();

    ArrayList<Region> existingMonitoredRegions = new ArrayList<>(mMonitoringStatus.regions());
    ArrayList<Region> existingRangedRegions = new ArrayList<>(mRangedRegionState.keySet());
    ArrayList<Region> newMonitoredRegions = new ArrayList<>(beaconManager.getMonitoredRegions());
    ArrayList<Region> newRangedRegions = new ArrayList<>(beaconManager.getRangedRegions());
    LogManager.d(TAG, "ranged regions: old="+existingRangedRegions.size()+" new="+newRangedRegions.size());
    LogManager.d(TAG, "monitored regions: old="+existingMonitoredRegions.size()+" new="+newMonitoredRegions.size());

    for (Region newRangedRegion: newRangedRegions) {
        if (!existingRangedRegions.contains(newRangedRegion)) {
            LogManager.d(TAG, "Starting ranging region: "+newRangedRegion);
            mRangedRegionState.put(newRangedRegion, new RangeState(new Callback(mContext.getPackageName())));
        }
    }
    for (Region existingRangedRegion: existingRangedRegions) {
        if (!newRangedRegions.contains(existingRangedRegion)) {
            LogManager.d(TAG, "Stopping ranging region: "+existingRangedRegion);
            mRangedRegionState.remove(existingRangedRegion);
        }
    }
    LogManager.d(TAG, "Updated state with "+newRangedRegions.size()+" ranging regions and "+newMonitoredRegions.size()+" monitoring regions.");

    this.save();
}
 
Example #9
Source File: BeaconScanDialogFragment.java    From PresencePublisher with MIT License 5 votes vote down vote up
public static BeaconScanDialogFragment getInstance(Context context, DialogCallback dialogCallback, Set<String> knownBeacons) {
    BeaconScanDialogFragment fragment = new BeaconScanDialogFragment();
    fragment.setLeScanner(CycledLeScanner.createScanner(context, SCAN_TIME_MILLIS, 0L, false,
            fragment.new ScanCallback(), null));
    fragment.setBeaconParsers(BeaconManager.getInstanceForApplication(context.getApplicationContext()).getBeaconParsers());
    fragment.setDialogCallback(dialogCallback);
    fragment.setKnownBeacons(knownBeacons);
    return fragment;
}
 
Example #10
Source File: ScanHelper.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Override
@MainThread
@SuppressLint("WrongThread")
public void onCycleEnd() {
    if (BeaconManager.getBeaconSimulator() != null) {
        LogManager.d(TAG, "Beacon simulator enabled");
        // if simulatedScanData is provided, it will be seen every scan cycle.  *in addition* to anything actually seen in the air
        // it will not be used if we are not in debug mode
        if (BeaconManager.getBeaconSimulator().getBeacons() != null) {
            if (0 != (mContext.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
                LogManager.d(TAG, "Beacon simulator returns "+BeaconManager.getBeaconSimulator().getBeacons().size()+" beacons.");
                for (Beacon beacon : BeaconManager.getBeaconSimulator().getBeacons()) {
                    // This is an expensive call and we do not want to block the main thread.
                    // But here we are in debug/test mode so we allow it on the main thread.
                    //noinspection WrongThread
                    processBeaconFromScan(beacon);
                }
            } else {
                LogManager.w(TAG, "Beacon simulations provided, but ignored because we are not running in debug mode.  Please remove beacon simulations for production.");
            }
        } else {
            LogManager.w(TAG, "getBeacons is returning null. No simulated beacons to report.");
        }
    }
    else {
        if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG, "Beacon simulator not enabled");
        }
    }
    mDistinctPacketDetector.clearDetections();
    mMonitoringStatus.updateNewlyOutside();
    processRangeData();
}
 
Example #11
Source File: ScanJobScheduler.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
private void applySettingsToScheduledJob(Context context, BeaconManager beaconManager, ScanState scanState) {
    scanState.applyChanges(beaconManager);
    LogManager.d(TAG, "Applying scan job settings with background mode "+scanState.getBackgroundMode());

    // if this is the first time we want to schedule a job and we are in background mode
    // trigger an immediate scan job in order to install the hw filter
    boolean startBackgroundImmediateScan = false;
    if (this.mBackgroundScanJobFirstRun && scanState.getBackgroundMode()) {
        LogManager.d(TAG, "This is the first time we schedule a job and we are in background, set immediate scan flag to true in order to trigger the HW filter install.");
        startBackgroundImmediateScan = true;
    }

    schedule(context, scanState, startBackgroundImmediateScan);
}
 
Example #12
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 #13
Source File: ScanJob.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
private boolean startScanning() {
    BeaconManager beaconManager = BeaconManager.getInstanceForApplication(getApplicationContext());
    beaconManager.setScannerInSameProcess(true);
    if (beaconManager.isMainProcess()) {
        LogManager.i(TAG, "scanJob version %s is starting up on the main process", BuildConfig.VERSION_NAME);
    }
    else {
        LogManager.i(TAG, "beaconScanJob library version %s is starting up on a separate process", BuildConfig.VERSION_NAME);
        ProcessUtils processUtils = new ProcessUtils(ScanJob.this);
        LogManager.i(TAG, "beaconScanJob PID is "+processUtils.getPid()+" with process name "+processUtils.getProcessName());
    }
    ModelSpecificDistanceCalculator defaultDistanceCalculator =  new ModelSpecificDistanceCalculator(ScanJob.this, BeaconManager.getDistanceModelUpdateUrl());
    Beacon.setDistanceCalculator(defaultDistanceCalculator);
    return restartScanning();
}
 
Example #14
Source File: RegionMonitoringState.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
public boolean markOutsideIfExpired() {
    if (inside) {
        if (lastSeenTime > 0 && SystemClock.elapsedRealtime() - lastSeenTime > BeaconManager.getRegionExitPeriod()) {
            LogManager.d(TAG, "We are newly outside the region because the lastSeenTime of %s "
                            + "was %s seconds ago, and that is over the expiration duration "
                            + "of %s", lastSeenTime, SystemClock.elapsedRealtime() - lastSeenTime,
                    BeaconManager.getRegionExitPeriod());
            markOutside();
            return true;
        }
    }
    return false;
}
 
Example #15
Source File: BeaconService.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
private void startForegroundIfConfigured() {
    BeaconManager beaconManager = BeaconManager.getInstanceForApplication(
            this.getApplicationContext());
    Notification notification = beaconManager
            .getForegroundServiceNotification();
    int notificationId = beaconManager
            .getForegroundServiceNotificationId();
    if (notification != null &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        this.startForeground(notificationId, notification);
    }
}
 
Example #16
Source File: RangingDataTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    LogManager.setLogger(Loggers.verboseLogger());
    LogManager.setVerboseLoggingEnabled(true);
    BeaconManager.setsManifestCheckingDisabled(true);
}
 
Example #17
Source File: RangedBeacon.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
private RssiFilter getFilter() {
    if (mFilter == null) {
        //set RSSI filter
        try {
        Constructor cons = BeaconManager.getRssiFilterImplClass().getConstructors()[0];
            mFilter = (RssiFilter)cons.newInstance();
        } catch (Exception e) {
            LogManager.e(TAG, "Could not construct RssiFilterImplClass %s", BeaconManager.getRssiFilterImplClass().getName());
        }
    }
    return mFilter;
}
 
Example #18
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 #19
Source File: SettingsData.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
public SettingsData collect(@NonNull Context context) {
    BeaconManager beaconManager = BeaconManager.getInstanceForApplication(context);
    mBeaconParsers = new ArrayList<>(beaconManager.getBeaconParsers());
    mRegionStatePersistenceEnabled = beaconManager.isRegionStatePersistenceEnabled();
    mAndroidLScanningDisabled = beaconManager.isAndroidLScanningDisabled();
    mRegionExitPeriod = BeaconManager.getRegionExitPeriod();
    mUseTrackingCache = RangeState.getUseTrackingCache();
    mHardwareEqualityEnforced = Beacon.getHardwareEqualityEnforced();
    return this;
}
 
Example #20
Source File: BeaconServiceTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    LogManager.setLogger(Loggers.verboseLogger());
    LogManager.setVerboseLoggingEnabled(true);
    BeaconManager.setsManifestCheckingDisabled(true);
}
 
Example #21
Source File: CycledLeScanner.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
public static CycledLeScanner createScanner(Context context, long scanPeriod, long betweenScanPeriod, boolean backgroundFlag, CycledLeScanCallback cycledLeScanCallback, BluetoothCrashResolver crashResolver) {
    boolean useAndroidLScanner = false;
    boolean useAndroidOScanner = false;
    if (android.os.Build.VERSION.SDK_INT < 18) {
        LogManager.w(TAG, "Not supported prior to API 18.");
        return null;
    }

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        LogManager.i(TAG, "This is pre Android 5.0.  We are using old scanning APIs");
        useAndroidLScanner = false;

    }
    else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        if (BeaconManager.isAndroidLScanningDisabled()) {
            LogManager.i(TAG, "This is Android 5.0, but L scanning is disabled. We are using old scanning APIs");
            useAndroidLScanner = false;
        } else {
            LogManager.i(TAG, "This is Android 5.0.  We are using new scanning APIs");
            useAndroidLScanner = true;
        }
    }
    else {
        LogManager.i(TAG, "Using Android O scanner");
        useAndroidOScanner = true;
    }

    if (useAndroidOScanner) {
        return new CycledLeScannerForAndroidO(context, scanPeriod, betweenScanPeriod, backgroundFlag, cycledLeScanCallback, crashResolver);
    }
    else if (useAndroidLScanner) {
        return new CycledLeScannerForLollipop(context, scanPeriod, betweenScanPeriod, backgroundFlag, cycledLeScanCallback, crashResolver);
    } else {
        return new CycledLeScannerForJellyBeanMr2(context, scanPeriod, betweenScanPeriod, backgroundFlag, cycledLeScanCallback, crashResolver);
    }
}
 
Example #22
Source File: MonitoringStatusTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    LogManager.setLogger(Loggers.verboseLogger());
    LogManager.setVerboseLoggingEnabled(true);
    BeaconManager.setManifestCheckingDisabled(true);
    Context context = RuntimeEnvironment.application;
    new MonitoringStatus(context).clear();
}
 
Example #23
Source File: MonitoringStatusTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void allowsAccessToRegionsAfterRestore() throws Exception {
    Context context = RuntimeEnvironment.application;
    BeaconManager beaconManager = BeaconManager.getInstanceForApplication(context);
    MonitoringStatus monitoringStatus = MonitoringStatus.getInstanceForApplication(context);
    for (int i = 0; i < 50; i++) {
        Region region = new Region(""+i, null, null, null);
        monitoringStatus.addRegion(region, null);
    }
    monitoringStatus.saveMonitoringStatusIfOn();
    monitoringStatus.restoreMonitoringStatus();
    Collection<Region> regions = beaconManager.getMonitoredRegions();
    assertEquals("beaconManager should return restored regions", 50, regions.size());
}
 
Example #24
Source File: ScanStateTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    LogManager.setLogger(Loggers.verboseLogger());
    LogManager.setVerboseLoggingEnabled(true);
    BeaconManager.setsManifestCheckingDisabled(true);
}
 
Example #25
Source File: BackgroundPowerSaver.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new BackgroundPowerSaver using the default background determination strategy
 *
 * @param context
 */
public BackgroundPowerSaver(Context context) {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        LogManager.w(TAG, "BackgroundPowerSaver requires API 18 or higher.");
    }
    beaconManager = BeaconManager.getInstanceForApplication(context);
    ((Application)context.getApplicationContext()).registerActivityLifecycleCallbacks(this);
}
 
Example #26
Source File: AltBeaconScannerService.java    From com.ruuvi.station with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Foreground.init(getApplication());
    Foreground.get().addListener(listener);

    Log.d(TAG, "Starting service");
    beaconManager = BeaconManager.getInstanceForApplication(this);
    Utils.setAltBeaconParsers(beaconManager);
    beaconManager.setBackgroundScanPeriod(5000);
    region = new Region("com.ruuvi.station.leRegion", null, null, null);
    beaconManager.bind(this);
}
 
Example #27
Source File: RuuviScannerApplication.java    From com.ruuvi.station with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void bindBeaconManager(BeaconConsumer consumer, Context context) {
    if (beaconManager == null) {
        beaconManager = BeaconManager.getInstanceForApplication(context.getApplicationContext());
        Utils.setAltBeaconParsers(beaconManager);
        beaconManager.setBackgroundScanPeriod(5000);
        beaconManager.bind(consumer);
    } else if (!running) {
        running = true;
        try {
            beaconManager.startRangingBeaconsInRegion(region);
        } catch (Exception e) {
            Log.d(TAG, "Could not start ranging again");
        }
    }
}
 
Example #28
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 #29
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 #30
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);
}