requestLocationUpdates

时间:2016-08-12 10:25:24

标签: android

我正在开发一个Android应用程序,它每5分钟给我一次位置。现在,如果用户接到一个电话,那么我正在更新5分钟到5秒,这样我就可以在每隔5秒的时间间隔内获得用户位置,直到他正在通话,这样我就能计算出他的速度。随叫随到。我每5分钟获得一次用户位置工作正常,但是当我在CALL_STATE_OFFHOOK中将此时间更新为5秒时,它没有将时间更新为5秒。我将在5分钟内获得位置。请帮助

 @Override
public void onCallStateChanged(int state, String incomingNumber) {
    super.onCallStateChanged(state, incomingNumber);
    log.info("onCallStateChanged called");

    switch (state) {
    case TelephonyManager.CALL_STATE_IDLE:
        BackgroundService.LOCATION_INTERVAL = 300000;
        log.info("onCallStateChanged  CALL_STATE_IDLE():");
        //Toast.makeText(context, "Phone state Idle", Toast.LENGTH_LONG).show();
        break;
    case TelephonyManager.CALL_STATE_OFFHOOK:
        BackgroundService.LOCATION_INTERVAL = 5000;
        log.info("onCallStateChanged  CALL_STATE_OFFHOOK()");
        //Toast.makeText(context, "Phone state Off hook", Toast.LENGTH_LONG).show();
        break;
      case TelephonyManager.CALL_STATE_RINGING:
          log.info("call state ringing before");
         // BackgroundService.LOCATION_INTERVAL = 00000;
          log.info("call state ringing after");
        //Toast.makeText(context, "Phone state Ringing", Toast.LENGTH_LONG).show();
        break;
    default:
        break;
    }

}

@Override
public void onCreate() {
    this.isRunning = false;
    this.backgroundThread = new Thread(myTask);
    log.info("on create run");
}

private Runnable myTask = new Runnable() {
    public void run() {
        initializeLocationManager();
        try {
            mLocationManager.requestLocationUpdates(
                    LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL,
                    LOCATION_DISTANCE, mLocationListeners[1],
                    Looper.getMainLooper());
            log.info("Location Interval" +LOCATION_INTERVAL);
        } catch (java.lang.SecurityException ex) {
            log.info("fail to request location update, ignore");
            Log.i(TAG, "fail to request location update, ignore", ex);
        } catch (IllegalArgumentException ex) {
            Log.d(TAG,
                    "network provider does not exist, " + ex.getMessage());
        }
        try {
            mLocationManager.requestLocationUpdates(
                    LocationManager.GPS_PROVIDER, LOCATION_INTERVAL,
                    LOCATION_DISTANCE, mLocationListeners[0],
                    Looper.getMainLooper());
        } catch (java.lang.SecurityException ex) {
            Log.i(TAG, "fail to request location update, ignore", ex);
        } catch (IllegalArgumentException ex) {
            Log.d(TAG, "gps provider does not exist " + ex.getMessage());
        }
    }
};

0 个答案:

没有答案