1

这是我的代码:我在onResume()

@Override
protected void onResume() {
    labaLocationListener = new LabaLocationListener(this);
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String bestProvider = locationManager.getBestProvider(criteria, true);
    if (StringUtils.isEmpty(bestProvider)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_MIN_TIME,
                LOCATION_MIN_DESTANCE, labaLocationListener);
    } else {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOCATION_MIN_TIME,
                LOCATION_MIN_DESTANCE, labaLocationListener);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_MIN_TIME,
                LOCATION_MIN_DESTANCE, labaLocationListener);
    }
    super.onResume();
}`

这是听众:

public class LabaLocationListener implements LocationListener {

public static double longitude;
public static double latitude;

private Activity activity;

public LabaLocationListener() {}

public LabaLocationListener(Activity activity) {
    this.activity = activity;
}


@Override
public void onLocationChanged(Location location) {

    longitude = location.getLongitude();
    latitude = location.getLatitude();
    Log.w("onLocationChanged", "longitude = " + longitude + ",latitude = "+latitude);

    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(activity);
    boolean isFirstTime = prefs.getBoolean(LabaConstants.IS_FIRST_TIME_USE_SYSTEM, true);
    if(isFirstTime){
         Editor  editor = prefs.edit();
         editor.putBoolean(LabaConstants.IS_FIRST_TIME_USE_SYSTEM, false);
         editor.commit();
         new SetDefaultCityTask(activity).execute();
    }


    //update user location
    int customerRadar = prefs.getInt(LabaConstants.CUSTOMER_RADAR, 0);
    if(customerRadar == 1){
        long userId = prefs.getLong(LabaConstants.USER_ID, 0);
        if(userId != 0){
            String url = activity.getString(R.string.product_url) + "updateCurrentLocation";
            RequestParams requestParams = new RequestParams();
            requestParams.put("latitude", String.valueOf(latitude));
            requestParams.put("longitude", String.valueOf(longitude));
            HttpUtil.get(url, requestParams,activity.getApplication(),
                    new AsyncHttpResponseHandler() {
                        @Override
                        public void onSuccess(String response) {
                            Log.w("","updateCurrentLocation = "+response);
                        }
            }); 
        }
    }

}

@Override
public void onProviderDisabled(String provider) {
    Log.w("", "onProviderDisabled");

}

@Override
public void onProviderEnabled(String provider) {
    Log.w("", "onProviderDisabled");
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    Log.w("", "onStatusChanged");
}
}

onLocationChanged 没有拨打某些电话,这很奇怪,有人能告诉我为什么吗?

4

0 回答 0