-
@RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) public final class PhoneNumberUtils
-
-
Method Summary
Modifier and Type Method Description static Stringformat(@NonNull() String phoneNumber, @NonNull() CountryInfo countryInfo)This method works as follow: - When the android version is LOLLIPOP or greater, thereliable {formatNumberToE164} is used toformat.
- For lower versions, we construct a value with the input phone numberstripped of non numeric characters and prefix it with a "+" and country code
static StringformatUsingCurrentCountry(@NonNull() String phoneNumber, Context context)This method uses the country returned by getCurrentCountryInfo to formatthe phone number. static CountryInfogetCurrentCountryInfo(@NonNull() Context context)static PhoneNumbergetPhoneNumber(@NonNull() String providedPhoneNumber)This method should not be called on UI thread. static booleanisValid(@NonNull() String number)static booleanisValidIso(@Nullable() String iso)static PhoneNumbergetPhoneNumber(@NonNull() String providedCountryIso, @NonNull() String providedNationalNumber)static IntegergetCountryCode(String countryIso)static Map<String, Integer>getImmutableCountryIsoMap()static List<String>getCountryIsosFromCountryCode(String countryCode)-
-
Method Detail
-
format
static String format(@NonNull() String phoneNumber, @NonNull() CountryInfo countryInfo)
This method works as follow:
- When the android version is LOLLIPOP or greater, thereliable {formatNumberToE164} is used toformat.
- For lower versions, we construct a value with the input phone numberstripped of non numeric characters and prefix it with a "+" and country code
- Parameters:
phoneNumber- that may or may not itself have country codecountryInfo- must have locale with ISO 3166 2-letter code for country
-
formatUsingCurrentCountry
@Nullable() static String formatUsingCurrentCountry(@NonNull() String phoneNumber, Context context)
This method uses the country returned by getCurrentCountryInfo to formatthe phone number. Internally invokes format
- Parameters:
phoneNumber- that may or may not itself have country code
-
getCurrentCountryInfo
@NonNull() static CountryInfo getCurrentCountryInfo(@NonNull() Context context)
-
getPhoneNumber
static PhoneNumber getPhoneNumber(@NonNull() String providedPhoneNumber)
This method should not be called on UI thread. Potentially creates a country code by iso mapwhich can take long in some devices
- Parameters:
providedPhoneNumber- works best when formatted as e164
-
isValidIso
static boolean isValidIso(@Nullable() String iso)
-
getPhoneNumber
static PhoneNumber getPhoneNumber(@NonNull() String providedCountryIso, @NonNull() String providedNationalNumber)
-
getCountryCode
@Nullable() static Integer getCountryCode(String countryIso)
-
getImmutableCountryIsoMap
static Map<String, Integer> getImmutableCountryIsoMap()
-
getCountryIsosFromCountryCode
@Nullable() static List<String> getCountryIsosFromCountryCode(String countryCode)
-
-
-