Country Detector
Resolves the user's likely country.
A fun interface so a host can supply one inline — commonly to add a backend/IP lookup ahead of the device signals:
val detector = CountryDetector {
api.geoCountry()?.let { CountryDetectionResult.detected(it, CountryDetectionSource.Network) }
?: DefaultCountryDetector(context).detectCountry()
}Rules the library relies on
No location permission. Country-level detection never justifies a runtime permission prompt; SIM, network and locale are enough. Implementations must not request one.
Never called from composition. detectCountry is
suspendand is invoked from aLaunchedEffect, so a network-backed implementation is free to block for as long as it needs.Detection is a suggestion, not a command. An explicit user selection always outranks a detection result; see com.ezzy.ccp.countrypicker.state.CountryPickerState.
Inheritors
Functions
Returns the detected country, or CountryDetectionResult.Unavailable when nothing could be determined. Implementations should not throw; failures are a result, not an exception.
Builds a detector that tries the receiver first and falls back to fallback when it yields nothing.