@Override
    public void handleMessage(Message msg) {
      IBeaconService service = mService.get();
      StartRMData startRMData = (StartRMData) msg.obj;

      if (service != null) {
        switch (msg.what) {
          case MSG_START_RANGING:
            Log.d(TAG, "start ranging received");
            service.startRangingBeaconsInRegion(
                startRMData.getRegionData(),
                new com.radiusnetworks.ibeacon.service.Callback(
                    msg.replyTo, startRMData.getIntentActionForCallback()));
            break;
          case MSG_STOP_RANGING:
            Log.d(TAG, "stop ranging received");
            service.stopRangingBeaconsInRegion(startRMData.getRegionData());
            break;
          case MSG_START_MONITORING:
            Log.d(TAG, "start monitoring received");
            service.startMonitoringBeaconsInRegion(
                startRMData.getRegionData(),
                new com.radiusnetworks.ibeacon.service.Callback(
                    msg.replyTo, startRMData.getIntentActionForCallback()));
            break;
          case MSG_STOP_MONITORING:
            Log.d(TAG, "stop monitoring received");
            service.stopMonitoringBeaconsInRegion(startRMData.getRegionData());
            break;

          default:
            super.handleMessage(msg);
        }
      }
    }
    @Override
    public void handleMessage(Message msg) {
      IBeaconService service = mService.get();
      StartRMData startRMData = (StartRMData) msg.obj;

      if (service != null) {
        switch (msg.what) {
          case MSG_START_RANGING:
            Log.d(TAG, "start ranging received");
            service.startRangingBeaconsInRegion(
                startRMData.getRegionData(),
                new com.radiusnetworks.ibeacon.service.Callback(
                    startRMData.getCallbackPackageName()));
            service.setScanPeriods(startRMData.getScanPeriod(), startRMData.getBetweenScanPeriod());
            break;
          case MSG_STOP_RANGING:
            Log.d(TAG, "stop ranging received");
            service.stopRangingBeaconsInRegion(startRMData.getRegionData());
            service.setScanPeriods(startRMData.getScanPeriod(), startRMData.getBetweenScanPeriod());
            break;
          case MSG_START_MONITORING:
            Log.d(TAG, "start monitoring received");
            service.startMonitoringBeaconsInRegion(
                startRMData.getRegionData(),
                new com.radiusnetworks.ibeacon.service.Callback(
                    startRMData.getCallbackPackageName()));
            service.setScanPeriods(startRMData.getScanPeriod(), startRMData.getBetweenScanPeriod());
            break;
          case MSG_STOP_MONITORING:
            Log.d(TAG, "stop monitoring received");
            service.stopMonitoringBeaconsInRegion(startRMData.getRegionData());
            service.setScanPeriods(startRMData.getScanPeriod(), startRMData.getBetweenScanPeriod());
            break;
          case MSG_SET_SCAN_PERIODS:
            Log.d(TAG, "set scan intervals received");
            service.setScanPeriods(startRMData.getScanPeriod(), startRMData.getBetweenScanPeriod());
            break;
          default:
            super.handleMessage(msg);
        }
      }
    }