Permitir ingresar a la aplicación solo si al menos un proveedor de ubicación está habilitado en Android

StackOverflow https://stackoverflow.com/questions/9493874

Pregunta

En mi solicitud, el usuario debe tener al menos un proveedor de ubicación habilitado.Para saber si uno está habilitado, utilizo:

isGpsLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
                .isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

Ahora, creé una actividad de alerta de actividad que ninguna está habilitada y si el usuario selecciona "Habilitar GPS", abro las opciones de GPS con action_location_source_settings intent.

Quiero (después de la selección del usuario) para verificar si le permitió uno, y solo le permitirá continuar si lo hizo.

Tengo este código en el botón "Habilitar GPS"

showGpsOptions();
isGpsLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
                    .isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
                    .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (isGpsLocationEnabled || isNetworkLocationEnabled){
    Intent startIntent = new Intent(EnableLocationProviderActivity.this, SensingService.class);
    startService(startIntent);
} else {
    finish();
}

Mi problema es que ISGPSLOUCENABILITED y IsnetworkLocationEnabled nunca se actualizará con la selección de usuarios en la configuración de la red, ya que el código continúa su ejecución después de Showgpsoptions () (Sé que no puede bloquear el hilo de la interfaz de usuario, pero ¿cómo puedo superar a esta situación) ??

¿Hay alguna manera de ejecutar código después de que el usuario selecciona algo en la configuración de la red?

¡Gracias!Guillermo.

¿Fue útil?

Solución

Cuando configuración de configuración viene delante de su activity, lógicamente y acc a docs, su activity es paused y luego cuando se requiere que su activity es resumed ... así que supongo que debe usarEl código de control en onResume ...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top