DefaultCountryDetector

Detects the country from device signals only: SIM → network → locale settings.

This is the same ladder the library has always used (previously com.ezzy.ccp.utils.CountryDetector on Android), behind the CountryDetector interface, reporting which signal won, and off the main thread.

Why these signals, in this order

The SIM's registered country is the strongest available claim about where the user actually is. The attached network is next, and can differ while roaming. The device locale is last and weakest — plenty of people run an English (US) device in Nairobi — so it is used only as a fallback, and reported as Based on your device language rather than as a location claim.

Per platform

  • Android reads TelephonyManager.simCountryIso and networkCountryIso, then the configuration locale and the default locale. Create it with DefaultCountryDetector(context).

  • iOS has no public SIM or network country API any more (CoreTelephony's carrier properties have returned placeholder values since iOS 16), so it goes straight to the user's Region setting — which on iOS is an explicit choice, and a better signal than an Android locale. Create it with DefaultCountryDetector().

From common code, rememberDefaultCountryDetector builds the right one for the platform.

No location permission is requested or required on either platform.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun detectCountry(): CountryDetectionResult

Returns the detected country, or CountryDetectionResult.Unavailable when nothing could be determined. Implementations should not throw; failures are a result, not an exception.

Link copied to clipboard

Builds a detector that tries the receiver first and falls back to fallback when it yields nothing.