繁体   English   中英

使用android 4.1.1在Galaxy S3中不调用onLocationChanged

[英]onLocationChanged is not called in Galaxy S3 with android 4.1.1

这个代码在其他手机上工作得很好,并且在三星Galaxy s3和Android 4.0.3中也可以正常工作,但是在三星Galaxy S3中使用android 4.1.1不行,任何想法?

问题是onLocationChanged方法不会被称为never。

返回的提供商是“网络”

/**
* @see android.app.Application#onCreate()
*/
@Override
public void onCreate() {
    locationManager = (LocationManager) this.getSystemService(getApplicationContext().LOCATION_SERVICE);
    String provider = getLocationProvider();
    locationManager.requestLocationUpdates(provider, 0, 20, locationListener);
}

/**
* @see android.location.LocationListener
*/
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
       currentLocationUser = location;
       if (onLocationListener != null) {
            onLocationListener.onLocationChanged(location);
       }
    }

   public void onStatusChanged(String provider, int status, Bundle extras) {

   } 

   public void onProviderEnabled(String provider) {

   }

    public void onProviderDisabled(String provider) {

    }
 };

public String getLocationProvider() {
    Criteria locationCriteria = new Criteria();
    locationCriteria.setAccuracy();
    return locationManager.getBestProvider(locationCriteria, true);
}

我想建议在使用新的时间请求更新之前使用LocationManager.removeUpdates() 在JELLYBEAN(4.1)之后,更新之间的最短时间不再仅仅是一个提示。

有关此信息,请参阅位置管理器

如下文所述

在Jellybean之前 ,minTime参数只是一个提示,一些位置提供程序实现忽略了它。 从Jellybean开始,Android兼容设备必须同时观察minTime和minDistance参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM