private void startMonitoring() {
   try {
     if (!beaconManager.isConnected()) {
       beaconManager.connect(
           new OnServiceBoundListener() {
             @Override
             public void onServiceBound() throws RemoteException {
               beaconManager.startMonitoring();
             }
           });
     }
   } catch (RemoteException e) {
     throw new IllegalStateException(e);
   }
 }
  @Override
  public void onCreate() {
    super.onCreate();

    beaconManager = BeaconManager.newInstance(this);
    beaconManager.setScanMode(BeaconManager.SCAN_MODE_BALANCED);
    beaconManager.setBeaconActivityCheckConfiguration(BeaconActivityCheckConfiguration.DEFAULT);
    beaconManager.setForceScanConfiguration(ForceScanConfiguration.DEFAULT);
    beaconManager.registerMonitoringListener(this);

    beaconManager.addFilter(
        new Filters.CustomFilter() {
          @Override
          public Boolean apply(AdvertisingPackage object) {
            final UUID proximityUUID = object.getProximityUUID();
            final double distance = object.getAccuracy();

            return proximityUUID.equals(BeaconManager.DEFAULT_KONTAKT_BEACON_PROXIMITY_UUID)
                && distance <= ACCEPT_DISTANCE;
          }
        });
  }
 private void stopMonitoring() {
   beaconManager.stopMonitoring();
 }
 @Override
 public void onDestroy() {
   super.onDestroy();
   beaconManager.disconnect();
   beaconManager = null;
 }