Search in sources :

Example 1 with StartRMData

use of org.altbeacon.beacon.service.StartRMData in project android-beacon-library by AltBeacon.

the class BeaconManager method updateScanPeriods.

/**
     * Updates an already running scan with scanPeriod/betweenScanPeriod according to Background/Foreground state.
     * Change will take effect on the start of the next scan cycle.
     *
     * @throws RemoteException - If the BeaconManager is not bound to the service.
     */
@TargetApi(18)
public void updateScanPeriods() throws RemoteException {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        LogManager.w(TAG, "Not supported prior to API 18.  Method invocation will be ignored");
        return;
    }
    if (serviceMessenger == null) {
        throw new RemoteException("The BeaconManager is not bound to the service.  Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()");
    }
    Message msg = Message.obtain(null, BeaconService.MSG_SET_SCAN_PERIODS, 0, 0);
    LogManager.d(TAG, "updating background flag to %s", mBackgroundMode);
    LogManager.d(TAG, "updating scan period to %s, %s", this.getScanPeriod(), this.getBetweenScanPeriod());
    StartRMData obj = new StartRMData(this.getScanPeriod(), this.getBetweenScanPeriod(), this.mBackgroundMode);
    msg.obj = obj;
    serviceMessenger.send(msg);
}
Also used : Message(android.os.Message) StartRMData(org.altbeacon.beacon.service.StartRMData) RemoteException(android.os.RemoteException) TargetApi(android.annotation.TargetApi)

Example 2 with StartRMData

use of org.altbeacon.beacon.service.StartRMData in project android-beacon-library by AltBeacon.

the class BeaconManager method stopMonitoringBeaconsInRegion.

/**
     * Tells the <code>BeaconService</code> to stop looking for beacons that match the passed
     * <code>Region</code> object.  Note that the Region's unique identifier is used to match it to
     * an existing monitored Region.
     *
     * @param region
     * @see BeaconManager#setMonitorNotifier(MonitorNotifier)
     * @see BeaconManager#startMonitoringBeaconsInRegion(Region region)
     * @see MonitorNotifier
     * @see Region
     */
@TargetApi(18)
public void stopMonitoringBeaconsInRegion(Region region) throws RemoteException {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        LogManager.w(TAG, "Not supported prior to API 18.  Method invocation will be ignored");
        return;
    }
    if (serviceMessenger == null) {
        throw new RemoteException("The BeaconManager is not bound to the service.  Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()");
    }
    Message msg = Message.obtain(null, BeaconService.MSG_STOP_MONITORING, 0, 0);
    StartRMData obj = new StartRMData(region, callbackPackageName(), this.getScanPeriod(), this.getBetweenScanPeriod(), this.mBackgroundMode);
    msg.obj = obj;
    serviceMessenger.send(msg);
}
Also used : Message(android.os.Message) StartRMData(org.altbeacon.beacon.service.StartRMData) RemoteException(android.os.RemoteException) TargetApi(android.annotation.TargetApi)

Example 3 with StartRMData

use of org.altbeacon.beacon.service.StartRMData in project android-beacon-library by AltBeacon.

the class BeaconManager method startRangingBeaconsInRegion.

/**
     * Tells the <code>BeaconService</code> to start looking for beacons that match the passed
     * <code>Region</code> object, and providing updates on the estimated mDistance every seconds while
     * beacons in the Region are visible.  Note that the Region's unique identifier must be retained to
     * later call the stopRangingBeaconsInRegion method.
     *
     * @param region
     * @see BeaconManager#setRangeNotifier(RangeNotifier)
     * @see BeaconManager#stopRangingBeaconsInRegion(Region region)
     * @see RangeNotifier
     * @see Region
     */
@TargetApi(18)
public void startRangingBeaconsInRegion(Region region) throws RemoteException {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        LogManager.w(TAG, "Not supported prior to API 18.  Method invocation will be ignored");
        return;
    }
    if (serviceMessenger == null) {
        throw new RemoteException("The BeaconManager is not bound to the service.  Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()");
    }
    Message msg = Message.obtain(null, BeaconService.MSG_START_RANGING, 0, 0);
    StartRMData obj = new StartRMData(region, callbackPackageName(), this.getScanPeriod(), this.getBetweenScanPeriod(), this.mBackgroundMode);
    msg.obj = obj;
    serviceMessenger.send(msg);
    synchronized (rangedRegions) {
        rangedRegions.add(region);
    }
}
Also used : Message(android.os.Message) StartRMData(org.altbeacon.beacon.service.StartRMData) RemoteException(android.os.RemoteException) TargetApi(android.annotation.TargetApi)

Example 4 with StartRMData

use of org.altbeacon.beacon.service.StartRMData in project android-beacon-library by AltBeacon.

the class BeaconManager method stopRangingBeaconsInRegion.

/**
     * Tells the <code>BeaconService</code> to stop looking for beacons that match the passed
     * <code>Region</code> object and providing mDistance information for them.
     *
     * @param region
     * @see #setMonitorNotifier(MonitorNotifier notifier)
     * @see #startMonitoringBeaconsInRegion(Region region)
     * @see MonitorNotifier
     * @see Region
     */
@TargetApi(18)
public void stopRangingBeaconsInRegion(Region region) throws RemoteException {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        LogManager.w(TAG, "Not supported prior to API 18.  Method invocation will be ignored");
        return;
    }
    if (serviceMessenger == null) {
        throw new RemoteException("The BeaconManager is not bound to the service.  Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()");
    }
    Message msg = Message.obtain(null, BeaconService.MSG_STOP_RANGING, 0, 0);
    StartRMData obj = new StartRMData(region, callbackPackageName(), this.getScanPeriod(), this.getBetweenScanPeriod(), this.mBackgroundMode);
    msg.obj = obj;
    serviceMessenger.send(msg);
    synchronized (rangedRegions) {
        Region regionToRemove = null;
        for (Region rangedRegion : rangedRegions) {
            if (region.getUniqueId().equals(rangedRegion.getUniqueId())) {
                regionToRemove = rangedRegion;
            }
        }
        rangedRegions.remove(regionToRemove);
    }
}
Also used : Message(android.os.Message) StartRMData(org.altbeacon.beacon.service.StartRMData) RemoteException(android.os.RemoteException) TargetApi(android.annotation.TargetApi)

Example 5 with StartRMData

use of org.altbeacon.beacon.service.StartRMData in project android-beacon-library by AltBeacon.

the class BeaconManager method applyChangesToServices.

@TargetApi(18)
private void applyChangesToServices(int type, Region region) throws RemoteException {
    if (!isAnyConsumerBound()) {
        LogManager.w(TAG, "The BeaconManager is not bound to the service.  Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()");
        return;
    }
    if (mIntentScanStrategyCoordinator != null) {
        mIntentScanStrategyCoordinator.applySettings();
        return;
    }
    if (mScheduledScanJobsEnabled) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ScanJobScheduler.getInstance().applySettingsToScheduledJob(mContext, this);
        }
        return;
    }
    Message msg = Message.obtain(null, type, 0, 0);
    if (type == BeaconService.MSG_SET_SCAN_PERIODS) {
        msg.setData(new StartRMData(this.getScanPeriod(), this.getBetweenScanPeriod(), this.mBackgroundMode).toBundle());
    } else if (type == BeaconService.MSG_SYNC_SETTINGS) {
        msg.setData(new SettingsData().collect(mContext).toBundle());
    } else {
        msg.setData(new StartRMData(region, callbackPackageName(), getScanPeriod(), getBetweenScanPeriod(), mBackgroundMode).toBundle());
    }
    serviceMessenger.send(msg);
}
Also used : SettingsData(org.altbeacon.beacon.service.SettingsData) Message(android.os.Message) StartRMData(org.altbeacon.beacon.service.StartRMData) TargetApi(android.annotation.TargetApi)

Aggregations

TargetApi (android.annotation.TargetApi)5 Message (android.os.Message)5 StartRMData (org.altbeacon.beacon.service.StartRMData)5 RemoteException (android.os.RemoteException)4 SettingsData (org.altbeacon.beacon.service.SettingsData)1