public class CountryDetector extends Object
The country will be detected in order of reliability, like
Call the detectCountry()
to get the available country immediately.
To be notified of the future country change, use the
addCountryListener(android.location.CountryListener, android.os.Looper)
You do not instantiate this class directly; instead, retrieve it through
Context.getSystemService(Context.COUNTRY_DETECTOR)
.
Both ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions are needed.
Constructor and Description |
---|
CountryDetector(ICountryDetector service) |
Modifier and Type | Method and Description |
---|---|
void |
addCountryListener(CountryListener listener,
Looper looper)
Add a listener to receive the notification when the country is detected
or changed.
|
Country |
detectCountry()
Start detecting the country that the user is in.
|
void |
removeCountryListener(CountryListener listener)
Remove the listener
|
public Country detectCountry()
public void addCountryListener(CountryListener listener, Looper looper)
listener
- will be called when the country is detected or changed.looper
- a Looper object whose message queue will be used to
implement the callback mechanism. If looper is null then the
callbacks will be called on the main thread.public void removeCountryListener(CountryListener listener)