我只是想听听GPS状态变化......我有以下几点:GPS状态监听
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
lm.addGpsStatusListener(new android.location.GpsStatus.Listener() {
public void onGpsStatusChanged(int event) {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
switch (event) {
case GPS_EVENT_STARTED:
if((alertDialog != null) && (alertDialog.isShowing())){
alertDialog.dismiss();
}
contador=0;
darHandle();
break;
case GPS_EVENT_STOPPED:
if(mProgressDialog!=null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
contador=0;
break;
}
}
});
它可以很好地在我的Moto G的第一次,但它已被弃用,不工作在一些设备中...
我试图找出如何使用“onProviderEnabled /无效”在那种情况下......我已经尝试了许多代码示例,但并没有得到它的工作...
我正在试试这个:
LocationListener locationListenerGps = new LocationListener() {
public void onLocationChanged(Location location) {
}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
};
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 12000, 0, locationListenerGps);
但在最后一行,它说:
无法解析法 'requestLocationUpdates(java.lang.String中,INT,INT,com.google.android.gms.location.LocationListener)'
我对Android/Java编程来说很新,任何人都可以帮助我?