简体   繁体   中英

How to check if the current Android device has Google's location service?

As we all know, some Android phones have no Google services, such as HUAWEI, ZTE and Samsung devices, so when using android.location.LocationManager and try to request current location with NetworkProvider, it always has no response. GPSProvider ("gps") works fine but it takes too much time when inside. So I'm now using a 3rd-party location provider which may not be accurate enough as a backup plan.

The question is I don't want to wait a time-out-period and apply the backup if the device has no Google Service, Is there any way to detect this while my application initializing?

I set a flag after the Google service response nothing for current, I wonder if there is an alternative.

Thank you :)

At last i use following strategy:

  1. Start to locate with both Google's and 3rd-party provider and wait till both provider returns (or time out).

  2. Check results, if Google's service failed, add a Boolean flag in preferences to indicate that the Google Location Services is not available in this device, and NEVER try to use Google's location Service if the flag is set.

  3. After a few days, run the steps above again to recheck.

That is a good question. I have never tried that. But there is a method on the LocationManager:

public List<String> getProviders (boolean enabledOnly)

Maybe you can use that?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM