Skip to content

Auto detect country

Harsh B. Bhakta edited this page Jul 18, 2020 · 4 revisions

CCP can auto detect user's country.

  • It can be enabled by adding XML property app:ccp_autoDetectCountry="true" in CCP view
  • Default value of app:ccp_autoDetectCountry is FALSE (Before 2.1.0, it was true which was confusing for many developers)
  • app:ccp_rememberLastSelection="true" can override auto detected country by last selected country
  • The country is detected at the runtime, so it can not be shown in the Android Studio preview of the layout.
  • SIM_NETWORK_LOCALE is the default preference order

Ways to detect country

Library uses 3 ways to detect user's location.

  1. Using SIM info
    • This will detect country from an inserted sim.
    • Devices without sim tray will not give expected result
    • Read more on official site.
  2. Using Network info
    • This will detect country from connected network's information
    • Read more in official site.
  3. Using Locale
    • Detect country from device's locale info.

Preference and order of options

  • Library provides flexibility when it comes to order of execution of these options.
  • Order can be specified with app:ccp_countryAutoDetectionPref="LOCALE_SIM"
  • e.g. "SIM_ONLY" will detect country from sim card. If it fails then ccp will reset to default country.
  • e.g. "SIM_NETWORK" will try from SIM details, if it fails then will try to find from network info then will reset to default country
  • e.g. "SIM_NETWORK_LOCALE" will follow SIM -> NETWORK -> LOCALE order.

All available options

  • SIM_ONLY
  • NETWORK_ONLY
  • LOCALE_ONLY
  • SIM_NETWORK
  • NETWORK_SIM
  • SIM_LOCALE
  • LOCALE_SIM
  • NETWORK_LOCALE
  • LOCALE_NETWORK
  • SIM_NETWORK_LOCALE
  • SIM_LOCALE_NETWORK
  • NETWORK_SIM_LOCALE
  • NETWORK_LOCALE_SIM
  • LOCALE_SIM_NETWORK
  • LOCALE_NETWORK_SIM

ccp_autoDetectCountry must be enabled to detect country at the time of layout prepartion

Clone this wiki locally