public class LocationBasedCountryDetector extends CountryDetectorBase
Use detectCountry()
to start querying. If the location can not be
resolved within the given time, the last known location will be used to get
the user country through the GeoCoder. The IllegalStateException will be
thrown if there is a ongoing query.
The current query can be stopped by stop()
Modifier and Type | Field and Description |
---|---|
protected List<LocationListener> |
mLocationListeners |
protected Thread |
mQueryThread
The thread to query the country from the GeoCoder.
|
protected Timer |
mTimer
Used for canceling location query
|
mContext, mDetectedCountry, mHandler, mListener
Constructor and Description |
---|
LocationBasedCountryDetector(Context ctx) |
Modifier and Type | Method and Description |
---|---|
Country |
detectCountry()
Start detecting the country.
|
protected String |
getCountryFromLocation(Location location) |
protected List<String> |
getEnabledProviders() |
protected Location |
getLastKnownLocation() |
protected long |
getQueryLocationTimeout() |
protected boolean |
isAcceptableProvider(String provider) |
protected void |
registerListener(String provider,
LocationListener listener)
Register a listener with a provider name
|
void |
stop()
Stop the current query without notifying the listener.
|
protected void |
unregisterListener(LocationListener listener)
Unregister an already registered listener
|
notifyListener, setCountryListener
protected Timer mTimer
protected Thread mQueryThread
protected List<LocationListener> mLocationListeners
public LocationBasedCountryDetector(Context ctx)
protected String getCountryFromLocation(Location location)
protected boolean isAcceptableProvider(String provider)
protected void registerListener(String provider, LocationListener listener)
protected void unregisterListener(LocationListener listener)
protected Location getLastKnownLocation()
protected long getQueryLocationTimeout()
public Country detectCountry()
Queries the location from all location providers, then starts a thread to query the country from GeoCoder.
detectCountry
in class CountryDetectorBase
public void stop()
stop
in class CountryDetectorBase