Class PhoneNumberUtils


  • public final class PhoneNumberUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String format​(java.lang.String phoneNumber, CountryInfo countryInfo)
      This method works as follow: When the android version is LOLLIPOP or greater, the reliable {PhoneNumberUtils.formatNumberToE164(java.lang.String, java.lang.String)} is used to format. 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
      static java.lang.String formatUsingCurrentCountry​(java.lang.String phoneNumber, android.content.Context context)
      This method uses the country returned by getCurrentCountryInfo(Context) to format the phone number.
      static java.lang.Integer getCountryCode​(java.lang.String countryIso)  
      static java.util.List<java.lang.String> getCountryIsosFromCountryCode​(java.lang.String countryCode)  
      static CountryInfo getCurrentCountryInfo​(android.content.Context context)  
      static java.util.Map<java.lang.String,​java.lang.Integer> getImmutableCountryIsoMap()  
      static PhoneNumber getPhoneNumber​(java.lang.String providedPhoneNumber)
      This method should not be called on UI thread.
      static PhoneNumber getPhoneNumber​(java.lang.String providedCountryIso, java.lang.String providedNationalNumber)  
      static boolean isValid​(java.lang.String number)  
      static boolean isValidIso​(java.lang.String iso)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PhoneNumberUtils

        public PhoneNumberUtils()
    • Method Detail

      • format

        public static java.lang.String format​(@NonNull
                                              java.lang.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
      • formatUsingCurrentCountry

        @Nullable
        public static java.lang.String formatUsingCurrentCountry​(@NonNull
                                                                 java.lang.String phoneNumber,
                                                                 android.content.Context context)
        This method uses the country returned by getCurrentCountryInfo(Context) to format the phone number. Internally invokes format(String, CountryInfo)
        Parameters:
        phoneNumber - that may or may not itself have country code
      • getCurrentCountryInfo

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

        public static PhoneNumber getPhoneNumber​(@NonNull
                                                 java.lang.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
                                      java.lang.String number)
      • isValidIso

        public static boolean isValidIso​(@Nullable
                                         java.lang.String iso)
      • getPhoneNumber

        public static PhoneNumber getPhoneNumber​(@NonNull
                                                 java.lang.String providedCountryIso,
                                                 @NonNull
                                                 java.lang.String providedNationalNumber)
        See Also:
        getPhoneNumber(String)
      • getCountryCode

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

        public static java.util.Map<java.lang.String,​java.lang.Integer> getImmutableCountryIsoMap()
      • getCountryIsosFromCountryCode

        @Nullable
        public static java.util.List<java.lang.String> getCountryIsosFromCountryCode​(java.lang.String countryCode)