android - Check Location Provider Status -


I'm creating a test project to learn how to use in Android.

I want as the default provider to use WiFi / 3G, but if there is set is not working (airplane mode on, for example), I switch to GPS Want to do

My idea is to check the NETWORK_PROVIDER status. If this is not available, then check GPS_PROVIDER status if it is also not available, do not use the location and show a message.

To do this, I need to check the current provider status, but I can not find the way. What is the way to do this?

I tried with the provider, but this method only tells me what the provider can use or not, but if not really capable.

The ideal idea is to call

before the call request and sorry for my english

to Czech this code

  location Manager mlocMan = (LocationManager) getSystemService (context.LOCATION_SERVICE); If (mlocMan .isProviderEnabled (LocationManager.GPS_PROVIDER) & amp ;! & amp ;! mlocMan .isProviderEnabled (LocationManager.NETWORK_PROVIDER)) {// both providers are disabled, will show a message ...}  

Edit:

  // -------------------------------- --- --------------------- private static boolean isAirplaneModeOn (references) {return Settings.System.getInt (context.getContentResolver (), Settings.System. AIRPLANE_MODE_ON, 0)! = 0; } Public void onCreate () {//. Some Code LocationManager mlocMan = (LocationManager) getSystemService (context.LOCATION_SERVICE); If (! IsAirplaneModeOn (this)) {// airplan, checks off provider, then (mlocMan.isProviderEnabled (LocationManager.NETWORK_PROVIDER) {// requestUpdates start listener ...} else {// NETWORK_PROVIDER disabled, GPS , try (mlocMan .isProviderEnabled (LocationManager.GPS_PROVIDER)) start listener {// requestUpdates ...} else {// show message, no providers enabled.}} // network disabled} else {// airplan mode Current // Here you only need to check the GPS, netwrok is fixed as if (mlocMan .isProviderEnabled (LocationManager.GPS_PROVIDER)) and {// requestUpdates to listener ... U} {// show message, a provider should be enabled.}} // airplan is ON} // onCreate ()  

may have some syntax errors, but I think That this argument is necessary for you.


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -