IT. Expert System.

Android Reference

PhoneNumberUtils


android.telephony

Class PhoneNumberUtils



  • public class PhoneNumberUtils
    extends Object
    Various utilities for dealing with phone number strings.
    • Constructor Detail

      • PhoneNumberUtils

        public PhoneNumberUtils()
    • Method Detail

      • isISODigit

        public static boolean isISODigit(char c)
        True if c is ISO-LATIN characters 0-9
      • is12Key

        public static final boolean is12Key(char c)
        True if c is ISO-LATIN characters 0-9, *, #
      • isDialable

        public static final boolean isDialable(char c)
        True if c is ISO-LATIN characters 0-9, *, # , +, WILD
      • isReallyDialable

        public static final boolean isReallyDialable(char c)
        True if c is ISO-LATIN characters 0-9, *, # , + (no WILD)
      • isNonSeparator

        public static final boolean isNonSeparator(char c)
        True if c is ISO-LATIN characters 0-9, *, # , +, WILD, WAIT, PAUSE
      • isStartsPostDial

        public static final boolean isStartsPostDial(char c)
        This any anything to the right of this char is part of the post-dial string (eg this is PAUSE or WAIT)
      • getNumberFromIntent

        public static String getNumberFromIntent(Intent intent,
                                 Context context)
        Extracts the phone number from an Intent.
        Parameters:
        intent - the intent to get the number of
        context - a context to use for database access
        Returns:
        the phone number that would be called by the intent, or null if the number cannot be found.
      • extractNetworkPortion

        public static String extractNetworkPortion(String phoneNumber)
        Extracts the network address portion and canonicalizes (filters out separators.) Network address portion is everything up to DTMF control digit separators (pause or wait), but without non-dialable characters. Please note that the GSM wild character is allowed in the result. This must be resolved before dialing. Returns null if phoneNumber == null
      • extractNetworkPortionAlt

        public static String extractNetworkPortionAlt(String phoneNumber)
        Extracts the network address portion and canonicalize. This function is equivalent to extractNetworkPortion(), except for allowing the PLUS character to occur at arbitrary positions in the address portion, not just the first position.
      • stripSeparators

        public static String stripSeparators(String phoneNumber)
        Strips separators from a phone number string.
        Parameters:
        phoneNumber - phone number to strip.
        Returns:
        phone string stripped of separators.
      • convertPreDial

        public static String convertPreDial(String phoneNumber)
        Converts pause and tonewait pause characters to Android representation. RFC 3601 says pause is 'p' and tonewait is 'w'.
      • extractPostDialPortion

        public static String extractPostDialPortion(String phoneNumber)
        Extracts the post-dial sequence of DTMF control digits, pauses, and waits. Strips separators. This string may be empty, but will not be null unless phoneNumber == null. Returns null if phoneNumber == null
      • compare

        public static boolean compare(String a,
                      String b)
        Compare phone numbers a and b, return true if they're identical enough for caller ID purposes.
      • compare

        public static boolean compare(Context context,
                      String a,
                      String b)
        Compare phone numbers a and b, and return true if they're identical enough for caller ID purposes. Checks a resource to determine whether to use a strict or loose comparison algorithm.
      • compare

        public static boolean compare(String a,
                      String b,
                      boolean useStrictComparation)
      • compareLoosely

        public static boolean compareLoosely(String a,
                             String b)
        Compare phone numbers a and b, return true if they're identical enough for caller ID purposes. - Compares from right to left - requires MIN_MATCH (7) characters to match - handles common trunk prefixes and international prefixes (basically, everything except the Russian trunk prefix) Note that this method does not return false even when the two phone numbers are not exactly same; rather; we can call this method "similar()", not "equals()".
      • compareStrictly

        public static boolean compareStrictly(String a,
                              String b)
      • compareStrictly

        public static boolean compareStrictly(String a,
                              String b,
                              boolean acceptInvalidCCCPrefix)
      • toCallerIDMinMatch

        public static String toCallerIDMinMatch(String phoneNumber)
        Returns the rightmost MIN_MATCH (5) characters in the network portion in *reversed* order This can be used to do a database lookup against the column that stores getStrippedReversed() Returns null if phoneNumber == null
      • getStrippedReversed

        public static String getStrippedReversed(String phoneNumber)
        Returns the network portion reversed. This string is intended to go into an index column for a database lookup. Returns null if phoneNumber == null
      • stringFromStringAndTOA

        public static String stringFromStringAndTOA(String s,
                                    int TOA)
        Basically: makes sure there's a + in front of a TOA_International number Returns null if s == null
      • toaFromString

        public static int toaFromString(String s)
        Returns the TOA for the given dial string Basically, returns TOA_International if there's a + prefix
      • calledPartyBCDToString

        public static String calledPartyBCDToString(byte[] bytes,
                                    int offset,
                                    int length)
        3GPP TS 24.008 10.5.4.7 Called Party BCD Number See Also TS 51.011 10.5.1 "dialing number/ssc string" and TS 11.11 "10.3.1 EF adn (Abbreviated dialing numbers)"
        Parameters:
        bytes - the data buffer
        offset - should point to the TOA (aka. TON/NPI) octet after the length byte
        length - is the number of bytes including TOA byte and must be at least 2
        Returns:
        partial string on invalid decode FIXME(mkf) support alphanumeric address type currently implemented in SMSMessage.getAddress()
      • calledPartyBCDFragmentToString

        public static String calledPartyBCDFragmentToString(byte[] bytes,
                                            int offset,
                                            int length)
        Like calledPartyBCDToString, but field does not start with a TOA byte. For example: SIM ADN extension fields
      • isWellFormedSmsAddress

        public static boolean isWellFormedSmsAddress(String address)
        Return true iff the network portion of address is, as far as we can tell on the device, suitable for use as an SMS destination address.
      • isGlobalPhoneNumber

        public static boolean isGlobalPhoneNumber(String phoneNumber)
      • networkPortionToCalledPartyBCD

        public static byte[] networkPortionToCalledPartyBCD(String s)
        Note: calls extractNetworkPortion(), so do not use for SIM EF[ADN] style records Returns null if network portion is empty.
      • numberToCalledPartyBCD

        public static byte[] numberToCalledPartyBCD(String number)
        Convert a dialing number to BCD byte array
        Parameters:
        number - dialing number string if the dialing number starts with '+', set to international TOA
        Returns:
        BCD byte array
      • formatNumber

        public static String formatNumber(String source)
        Breaks the given number down and formats it according to the rules for the country the number is from.
        Parameters:
        source - The phone number to format
        Returns:
        A locally acceptable formatting of the input, or the raw input if formatting rules aren't known for the number
      • formatNumber

        public static String formatNumber(String source,
                          int defaultFormattingType)
        Formats the given number with the given formatting type. Currently FORMAT_NANP and FORMAT_JAPAN are supported as a formating type.
        Parameters:
        source - the phone number to format
        defaultFormattingType - The default formatting rules to apply if the number does not begin with +[country_code]
        Returns:
        The phone number formatted with the given formatting type.
      • getFormatTypeForLocale

        public static int getFormatTypeForLocale(Locale locale)
        Returns the phone number formatting type for the given locale.
        Parameters:
        locale - The locale of interest, usually Locale.getDefault()
        Returns:
        The formatting type for the given locale, or FORMAT_UNKNOWN if the formatting rules are not known for the given locale
      • formatNumber

        public static void formatNumber(Editable text,
                        int defaultFormattingType)
        Formats a phone number in-place. Currently FORMAT_JAPAN and FORMAT_NANP is supported as a second argument.
        Parameters:
        text - The number to be formatted, will be modified with the formatting
        defaultFormattingType - The default formatting rules to apply if the number does not begin with +[country_code]
      • formatNanpNumber

        public static void formatNanpNumber(Editable text)
        Formats a phone number in-place using the NANP formatting rules. Numbers will be formatted as:

        xxxxx xxx-xxxx xxx-xxx-xxxx 1-xxx-xxx-xxxx +1-xxx-xxx-xxxx

        Parameters:
        text - the number to be formatted, will be modified with the formatting
      • formatJapaneseNumber

        public static void formatJapaneseNumber(Editable text)
        Formats a phone number in-place using the Japanese formatting rules. Numbers will be formatted as:

        03-xxxx-xxxx 090-xxxx-xxxx 0120-xxx-xxx +81-3-xxxx-xxxx +81-90-xxxx-xxxx

        Parameters:
        text - the number to be formatted, will be modified with the formatting
      • formatNumberToE164

        public static String formatNumberToE164(String phoneNumber,
                                String defaultCountryIso)
        Format the given phoneNumber to the E.164 representation.

        The given phone number must have an area code and could have a country code.

        The defaultCountryIso is used to validate the given number and generate the E.164 phone number if the given number doesn't have a country code.

        Parameters:
        phoneNumber - the phone number to format
        defaultCountryIso - the ISO 3166-1 two letters country code
        Returns:
        the E.164 representation, or null if the given phone number is not valid.
      • formatNumber

        public static String formatNumber(String phoneNumber,
                          String defaultCountryIso)
        Format a phone number.

        If the given number doesn't have the country code, the phone will be formatted to the default country's convention.

        Parameters:
        phoneNumber - the number to be formatted.
        defaultCountryIso - the ISO 3166-1 two letters country code whose convention will be used if the given number doesn't have the country code.
        Returns:
        the formatted number, or null if the given number is not valid.
      • formatNumber

        public static String formatNumber(String phoneNumber,
                          String phoneNumberE164,
                          String defaultCountryIso)
        Format the phone number only if the given number hasn't been formatted.

        The number which has only dailable character is treated as not being formatted.

        Parameters:
        phoneNumber - the number to be formatted.
        phoneNumberE164 - the E164 format number whose country code is used if the given phoneNumber doesn't have the country code.
        defaultCountryIso - the ISO 3166-1 two letters country code whose convention will be used if the phoneNumberE164 is null or invalid, or if phoneNumber contains IDD.
        Returns:
        the formatted number if the given number has been formatted, otherwise, return the given number.
      • normalizeNumber

        public static String normalizeNumber(String phoneNumber)
        Normalize a phone number by removing the characters other than digits. If the given number has keypad letters, the letters will be converted to digits first.
        Parameters:
        phoneNumber - the number to be normalized.
        Returns:
        the normalized number.
      • replaceUnicodeDigits

        public static String replaceUnicodeDigits(String number)
        Replace arabic/unicode digits with decimal digits.
        Parameters:
        number - the number to be normalized.
        Returns:
        the replaced number.
      • isEmergencyNumber

        public static boolean isEmergencyNumber(String number)
        Checks a given number against the list of emergency numbers provided by the RIL and SIM card.
        Parameters:
        number - the number to look up.
        Returns:
        true if the number is in the list of emergency numbers listed in the RIL / SIM, otherwise return false.
      • isPotentialEmergencyNumber

        public static boolean isPotentialEmergencyNumber(String number)
        Checks if given number might *potentially* result in a call to an emergency service on the current network. Specifically, this method will return true if the specified number is an emergency number according to the list managed by the RIL or SIM, *or* if the specified number simply starts with the same digits as any of the emergency numbers listed in the RIL / SIM. This method is intended for internal use by the phone app when deciding whether to allow ACTION_CALL intents from 3rd party apps (where we're required to *not* allow emergency calls to be placed.)
        Parameters:
        number - the number to look up.
        Returns:
        true if the number is in the list of emergency numbers listed in the RIL / SIM, *or* if the number starts with the same digits as any of those emergency numbers.
      • isEmergencyNumber

        public static boolean isEmergencyNumber(String number,
                                String defaultCountryIso)
        Checks if a given number is an emergency number for a specific country.
        Parameters:
        number - the number to look up.
        defaultCountryIso - the specific country which the number should be checked against
        Returns:
        if the number is an emergency number for the specific country, then return true, otherwise false
      • isPotentialEmergencyNumber

        public static boolean isPotentialEmergencyNumber(String number,
                                         String defaultCountryIso)
        Checks if a given number might *potentially* result in a call to an emergency service, for a specific country. Specifically, this method will return true if the specified number is an emergency number in the specified country, *or* if the number simply starts with the same digits as any emergency number for that country. This method is intended for internal use by the phone app when deciding whether to allow ACTION_CALL intents from 3rd party apps (where we're required to *not* allow emergency calls to be placed.)
        Parameters:
        number - the number to look up.
        defaultCountryIso - the specific country which the number should be checked against
        Returns:
        true if the number is an emergency number for the specific country, *or* if the number starts with the same digits as any of those emergency numbers.
      • isLocalEmergencyNumber

        public static boolean isLocalEmergencyNumber(String number,
                                     Context context)
        Checks if a given number is an emergency number for the country that the user is in. The current country is determined using the CountryDetector.
        Parameters:
        number - the number to look up.
        context - the specific context which the number should be checked against
        Returns:
        true if the specified number is an emergency number for a local country, based on the CountryDetector.
        See Also:
        CountryDetector
      • isPotentialLocalEmergencyNumber

        public static boolean isPotentialLocalEmergencyNumber(String number,
                                              Context context)
        Checks if a given number might *potentially* result in a call to an emergency service, for the country that the user is in. The current country is determined using the CountryDetector. Specifically, this method will return true if the specified number is an emergency number in the current country, *or* if the number simply starts with the same digits as any emergency number for the current country. This method is intended for internal use by the phone app when deciding whether to allow ACTION_CALL intents from 3rd party apps (where we're required to *not* allow emergency calls to be placed.)
        Parameters:
        number - the number to look up.
        context - the specific context which the number should be checked against
        Returns:
        true if the specified number is an emergency number for a local country, based on the CountryDetector.
        See Also:
        CountryDetector
      • isVoiceMailNumber

        public static boolean isVoiceMailNumber(String number)
        isVoiceMailNumber: checks a given number against the voicemail number provided by the RIL and SIM card. The caller must have the READ_PHONE_STATE credential.
        Parameters:
        number - the number to look up.
        Returns:
        true if the number is in the list of voicemail. False otherwise, including if the caller does not have the permission to read the VM number.
      • convertKeypadLettersToDigits

        public static String convertKeypadLettersToDigits(String input)
        Translates any alphabetic letters (i.e. [A-Za-z]) in the specified phone number into the equivalent numeric digits, according to the phone keypad letter mapping described in ITU E.161 and ISO/IEC 9995-8.
        Returns:
        the input string, with alpha letters converted to numeric digits using the phone keypad letter mapping. For example, an input of "1-800-GOOG-411" will return "1-800-4664-411".
      • cdmaCheckAndProcessPlusCode

        public static String cdmaCheckAndProcessPlusCode(String dialStr)
        This function checks if there is a plus sign (+) in the passed-in dialing number. If there is, it processes the plus sign based on the default telephone numbering plan of the system when the phone is activated and the current telephone numbering plan of the system that the phone is camped on. Currently, we only support the case that the default and current telephone numbering plans are North American Numbering Plan(NANP). The passed-in dialStr should only contain the valid format as described below, 1) the 1st character in the dialStr should be one of the really dialable characters listed below ISO-LATIN characters 0-9, *, # , + 2) the dialStr should already strip out the separator characters, every character in the dialStr should be one of the non separator characters listed below ISO-LATIN characters 0-9, *, # , +, WILD, WAIT, PAUSE Otherwise, this function returns the dial string passed in
        Parameters:
        dialStr - the original dial string
        Returns:
        the converted dial string if the current/default countries belong to NANP, and if there is the "+" in the original dial string. Otherwise, the original dial string returns. This API is for CDMA only
      • cdmaCheckAndProcessPlusCodeByNumberFormat

        public static String cdmaCheckAndProcessPlusCodeByNumberFormat(String dialStr,
                                                       int currFormat,
                                                       int defaultFormat)
        This function should be called from checkAndProcessPlusCode only And it is used for test purpose also. It checks the dial string by looping through the network portion, post dial portion 1, post dial porting 2, etc. If there is any plus sign, then process the plus sign. Currently, this function supports the plus sign conversion within NANP only. Specifically, it handles the plus sign in the following ways: 1)+1NANP,remove +, e.g. +18475797000 is converted to 18475797000, 2)+NANP or +non-NANP Numbers,replace + with the current NANP IDP, e.g, +8475797000 is converted to 0118475797000, +11875767800 is converted to 01111875767800 3)+1NANP in post dial string(s), e.g. 8475797000;+18475231753 is converted to 8475797000;18475231753
        Parameters:
        dialStr - the original dial string
        currFormat - the numbering system of the current country that the phone is camped on
        defaultFormat - the numbering system of the country that the phone is activated on
        Returns:
        the converted dial string if the current/default countries belong to NANP, and if there is the "+" in the original dial string. Otherwise, the original dial string returns.
      • isUriNumber

        public static boolean isUriNumber(String number)
        Determines if the specified number is actually a URI (i.e. a SIP address) rather than a regular PSTN phone number, based on whether or not the number contains an "@" character.
        Parameters:
        number -
        Returns:
        true if number contains @
      • getUsernameFromUriNumber

        public static String getUsernameFromUriNumber(String number)
        Parameters:
        number - SIP address of the form "username@domainname" (or the URI-escaped equivalent "username%40domainname")
        Returns:
        the "username" part of the specified SIP address, i.e. the part before the "@" character (or "%40").
        See Also:
        isUriNumber


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 758 / 158859806. Delta: 0.04384 с