Java Code Examples for org.altbeacon.beacon.BeaconManager#getInstanceForApplication()

The following examples show how to use org.altbeacon.beacon.BeaconManager#getInstanceForApplication() . 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: 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 7
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 8
Source File: StartupBroadcastReceiver.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    LogManager.d(TAG, "onReceive called in startup broadcast receiver");
    if (android.os.Build.VERSION.SDK_INT < 18) {
        LogManager.w(TAG, "Not starting up beacon service because we do not have API version 18 (Android 4.3).  We have: %s", android.os.Build.VERSION.SDK_INT);
        return;
    }
    BeaconManager beaconManager = BeaconManager.getInstanceForApplication(context.getApplicationContext());
    if (beaconManager.isAnyConsumerBound() || beaconManager.getScheduledScanJobsEnabled()) {
        int bleCallbackType = intent.getIntExtra(BluetoothLeScanner.EXTRA_CALLBACK_TYPE, -1); // e.g. ScanSettings.CALLBACK_TYPE_FIRST_MATCH
        if (bleCallbackType != -1) {
            LogManager.d(TAG, "Passive background scan callback type: "+bleCallbackType);
            LogManager.d(TAG, "got Android O background scan via intent");
            int errorCode = intent.getIntExtra(BluetoothLeScanner.EXTRA_ERROR_CODE, -1); // e.g.  ScanCallback.SCAN_FAILED_INTERNAL_ERROR
            if (errorCode != -1) {
                LogManager.w(TAG, "Passive background scan failed.  Code; "+errorCode);
            }
            ArrayList<ScanResult> scanResults = intent.getParcelableArrayListExtra(BluetoothLeScanner.EXTRA_LIST_SCAN_RESULT);
            ScanJobScheduler.getInstance().scheduleAfterBackgroundWakeup(context, scanResults);
        }
        else if (intent.getBooleanExtra("wakeup", false)) {
            LogManager.d(TAG, "got wake up intent");
        }
        else {
            LogManager.d(TAG, "Already started.  Ignoring intent: %s of type: %s", intent,
                    intent.getStringExtra("wakeup"));
        }
    }
    else {
        LogManager.d(TAG, "No consumers are bound.  Ignoring broadcast receiver.");
    }
 }
 
Example 9
Source File: ApplicationModule.java    From beaconloc with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public BeaconManager provideBeaconManager() {
    BeaconManager manager = BeaconManager.getInstanceForApplication(application);


    //manager.setDebug(true);
    return manager;
}
 
Example 10
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 11
Source File: ThunderBoardBootstrap.java    From thunderboard-android with Apache License 2.0 5 votes vote down vote up
public ThunderBoardBootstrap(Context context, RangeNotifier rangeNotifier, List<Region> regions) {
    this.context = context;
    beaconManager = BeaconManager.getInstanceForApplication(context);
    this.regions = regions;
    beaconConsumer = new InternalBeaconConsumer();
    beaconManager.bind(beaconConsumer);
    Timber.d("Waiting for BeaconService connection");
}
 
Example 12
Source File: ThunderBoardBootstrap.java    From thunderboard-android with Apache License 2.0 5 votes vote down vote up
public ThunderBoardBootstrap(Context context, RangeNotifier rangeNotifier, Region region) {
    this.context = context;
    this.rangeNotifier = rangeNotifier;
    beaconManager = BeaconManager.getInstanceForApplication(context);
    regions = new ArrayList<>();
    regions.add(region);
    beaconConsumer = new InternalBeaconConsumer();
    beaconManager.bind(beaconConsumer);
    Timber.d("Waiting for BeaconService connection");
}
 
Example 13
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 14
Source File: BeaconsAndroidModule.java    From react-native-beacons-android with MIT License 5 votes vote down vote up
public BeaconsAndroidModule(ReactApplicationContext reactContext) {
    super(reactContext);
    Log.d(LOG_TAG, "BeaconsAndroidModule - started");
    this.mReactContext = reactContext;
    this.mApplicationContext = reactContext.getApplicationContext();
    this.mBeaconManager = BeaconManager.getInstanceForApplication(mApplicationContext);
    // Detect iBeacons ( http://stackoverflow.com/questions/25027983/is-this-the-correct-layout-to-detect-ibeacons-with-altbeacons-android-beacon-li )
    addParser("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24");
    mBeaconManager.bind(this);
}
 
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: 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 17
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 18
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 19
Source File: ScanHelper.java    From android-beacon-library with Apache License 2.0 4 votes vote down vote up
ScanHelper(Context context) {
    mContext = context;
    mBeaconManager = BeaconManager.getInstanceForApplication(context);
}
 
Example 20
Source File: CycledLeScannerForLollipop.java    From android-beacon-library with Apache License 2.0 4 votes vote down vote up
public CycledLeScannerForLollipop(Context context, long scanPeriod, long betweenScanPeriod, boolean backgroundFlag, CycledLeScanCallback cycledLeScanCallback, BluetoothCrashResolver crashResolver) {
    super(context, scanPeriod, betweenScanPeriod, backgroundFlag, cycledLeScanCallback, crashResolver);
    mBeaconManager = BeaconManager.getInstanceForApplication(mContext);
    mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
}