Duplicar posibles:
Problems with getting gps status from the LocationManager in Androidescuchar LocationManager.GPS_PROVIDER no se dispara ningún evento LocationListener
Parece que cuando requestLocationUpdates I y escuchan LocationManager.GPS_PROVIDER I NO HAGO obtener cualquier evento, pero si escucho LocationManager.NETWORK_PROVIDER I DO obtener actualizaciones
Así que este, con NETWORK_PROVIDER funciona. Llego al método onLocationChanged:
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
textView.setText(textView.getText().toString() + "GOT SOMETHING\n");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
textView.setText(textView.getText().toString() + status + "onStatus Changed \n");
}
public void onProviderEnabled(String provider) {
textView.setText(textView.getText().toString() + "onProviderEnabled \n");
}
public void onProviderDisabled(String provider) {
textView.setText(textView.getText().toString() + "onProviderDisabled \n");
}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
Éste con GPS_PROVIDER no funciona. Nunca llego a ninguno de los métodos implementados. (OnLocationChanged, OnStatusChanged etc):
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
textView.setText(textView.getText().toString() + "GOT SOMETHING\n");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
textView.setText(textView.getText().toString() + status + "onStatus Changed \n");
}
public void onProviderEnabled(String provider) {
textView.setText(textView.getText().toString() + "onProviderEnabled \n");
}
public void onProviderDisabled(String provider) {
textView.setText(textView.getText().toString() + "onProviderDisabled \n");
}
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Es esto un error con Android?
Mi GPS está encendido y la barra de estado tiene el ícono de GPS en estado sólido. No sé si esto es importante, porque un montón que debería llegar a la OnStatusChanged en cualquiera de los casos ... Además, tengo el <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Creo que solo necesita ser paciente, puede tomar un tiempo para obtener una solución. Coloque el teléfono cerca de una ventana grande, o mejor aún salga si el clima está bien. Descargue también una de las aplicaciones de GPS gratuitas del mercado (por ejemplo, "Prueba de GPS"). Ese te dice cuántos satélites están a la vista. Vea cuánto tarda la aplicación gratuita en obtener una solución en comparación con la suya. – NickT
¿No debería al menos obtener el paquete onProviderEnabled/onProviderDisabled de inmediato? Ni siquiera esos son llamados. –
Suponiendo que actualmente está probando esto en un dispositivo, puede intentar probar esto en el emulador (después de suministrar coordenadas gps, por supuesto). Eso podría descartar problemas del dispositivo. Además, has probado la sugerencia de @NickT (Prueba de GPS). –