E 'possibile verificare se i servizi di Google Play sono disponibili. Segui le istruzioni qui: https://developer.android.com/training/location/retrieve-current.html
E 'possibile getLastLocation() restituirà null anche se i servizi di localizzazione di Google Play Services sono abilitati. Ad esempio, subito dopo averli riabilitati. Tuttavia si può quindi prendere il vostro utente ai servizi di Google Play località Impostazioni utilizzando il seguente intento:
Intent settings = new Intent("com.google.android.gms.location.settings.GOOGLE_LOCATION_SETTINGS");
startActivity(settings);
Infine, è anche possibile controllare se Android servizi di localizzazione sono abilitati:
public static boolean isLocationEnabled(Context context) {
int locationMode = 0;
String locationProviders;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
}else{
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
}
}
uso 'LocationManager' per controllare i diversi fornitori di – tyczj