ho il seguente codice e non è buona, perché a volte il GPS prende molto tempoCome posso controllare se il GPS è attivato prima che io cerco di usarlo
Come posso effettuare le seguenti operazioni:
- Controllare se il GPS è abilitato
- Utilizzare il GPS se è abilitato altrimenti utilizzare il provider di rete.
- Se il GPS impiega più di 30 secondi, utilizzare la rete.
posso fare questo con la mia logica con un tempo o Thread.sleep ma penso che ci potrebbe essere un modo più stabndard
// Acquire a reference to the system Location Manager
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.
locationCallback(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Ripensate alla vostra terza condizione. alzalo a 60 secondi. 30s funziona spesso solo con AGPS usando internet. – AlexWien