Package com.firebase.ui.auth.util.data
Class PhoneNumberUtils
- java.lang.Object
-
- com.firebase.ui.auth.util.data.PhoneNumberUtils
-
public final class PhoneNumberUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description PhoneNumberUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringformat(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 codestatic StringformatUsingCurrentCountry(String phoneNumber, Context context)This method uses the country returned bygetCurrentCountryInfo(Context)to format the phone number.static IntegergetCountryCode(String countryIso)static List<String>getCountryIsosFromCountryCode(String countryCode)static CountryInfogetCurrentCountryInfo(Context context)static Map<String,Integer>getImmutableCountryIsoMap()static PhoneNumbergetPhoneNumber(String providedPhoneNumber)This method should not be called on UI thread.static PhoneNumbergetPhoneNumber(String providedCountryIso, String providedNationalNumber)static booleanisValid(String number)static booleanisValidIso(String iso)
-
-
-
Method Detail
-
format
public static String format(@NonNull String phoneNumber, @NonNull 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
- Parameters:
phoneNumber- that may or may not itself have country codecountryInfo- must have locale with ISO 3166 2-letter code for country
- When the android version is LOLLIPOP or greater, the
reliable {
-
formatUsingCurrentCountry
@Nullable public static String formatUsingCurrentCountry(@NonNull String phoneNumber, Context context)
This method uses the country returned bygetCurrentCountryInfo(Context)to format the phone number. Internally invokesformat(String, CountryInfo)- Parameters:
phoneNumber- that may or may not itself have country code
-
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)
-
getPhoneNumber
public static PhoneNumber getPhoneNumber(@NonNull String providedCountryIso, @NonNull String providedNationalNumber)
- See Also:
getPhoneNumber(String)
-
-