Class PhoneNumberUtils


  • public final class PhoneNumberUtils
    extends Object
    • Constructor Detail

      • PhoneNumberUtils

        public PhoneNumberUtils()
    • Method Detail

      • format

        public static String format​(@NonNull
                                    String phoneNumber,
                                    @NonNull
                                    CountryInfo countryInfo)
        This method works as follow:
        1. When the android version is LOLLIPOP or greater, the reliable {PhoneNumberUtils.formatNumberToE164(java.lang.String, java.lang.String)} is used to format.
        2. For lower versions, we construct a value with the input phone number stripped of non numeric characters and prefix it with a "+" and country code
        Parameters:
        phoneNumber - that may or may not itself have country code
        countryInfo - must have locale with ISO 3166 2-letter code for country
      • getCurrentCountryInfo

        @NonNull
        public static CountryInfo getCurrentCountryInfo​(@NonNull
                                                        Context context)
      • getPhoneNumber

        public static PhoneNumber getPhoneNumber​(@NonNull
                                                 String providedPhoneNumber)
        This method should not be called on UI thread. Potentially creates a country code by iso map which can take long in some devices
        Parameters:
        providedPhoneNumber - works best when formatted as e164
        Returns:
        an instance of the PhoneNumber using the SIM information
      • isValid

        public static boolean isValid​(@NonNull
                                      String number)
      • isValidIso

        public static boolean isValidIso​(@Nullable
                                         String iso)
      • getCountryCode

        @Nullable
        public static Integer getCountryCode​(String countryIso)
      • getImmutableCountryIsoMap

        public static Map<String,​Integer> getImmutableCountryIsoMap()
      • getCountryIsosFromCountryCode

        @Nullable
        public static List<String> getCountryIsosFromCountryCode​(String countryCode)