1. 程式人生 > >Android中Telephony學習筆記(9)-Phone相關類

Android中Telephony學習筆記(9)-Phone相關類

PhoneNumberUtils

提供多種方法工具處理電話號碼字串,工具類。

Constants

FORMAT_JAPAN:日本區號列表

FORMAT_NANP:北美洲電話區號列表

FORMAT_UNKNOWN:未知地區

PAUSE

TOA_International

TOA_Unknown

WAIT

WILD

Methods

public static String calledPartyBCDFragmentToString(byte[] bytes, int offset, int length)

public static String calledPartyBCDToString
(byte[] bytes, int offset, int length)

public static boolean compare(String a, String b)

public static boolean compare(Context context, String a, String b)

public static String convertKeypadLettersToDigits(String input)

public static String extractNetworkPortion(String phoneNumber)

public static String
extractPostDialPortion(String phoneNumber)

public static void formatJapaneseNumber(Editable text)

public static void formatNanpNumber(Editable text)

public static String formatNumber(String source)

public static void formatNumber(Editable text, int defaultFormattingType)

public static int getFormatTypeForLocale
(Locale locale)

public static String getNumberFromIntent(Intent intent, Context context)

public static String getStrippedReversed(String phoneNumber)

public static final boolean isDialable (char c)

public static boolean isEmergencyNumber(String number)

public static boolean isGlobalPhoneNumber(String phoneNumber)

public static boolean isISODigit(char c)

public static final boolean isNonSeparator (char c)

public static final boolean isReallyDialable (char c)

public static final boolean isStartsPostDial (char c)

public static boolean isWellFormedSmsAddress(String address)

public static byte[] networkPortionToCalledPartyBCD(String s)

public static byte[] networkPortionToCalledPartyBCDWithLength(String s)

public static byte[] numberToCalledPartyBCD(String number)

public static String stringFromStringAndTOA(String s, int TOA)

public static String stripSeparators(String phoneNumber)

public static String toCallerIDMinMatch(String phoneNumber)

public static int toaFromString(String s)


對字串各種操作,提取到所需要的資訊。不做具體解釋了。

PhoneNumberFormattingTextWatcher

觀察TextView和輸入手機號碼時,該類提供監聽,嚴格規範手機號碼的格式。當用戶輸入無效的字元,或者刪除字串中間的分隔符該格式化watcher就停止工作。

Methods

public synchronized void afterTextChanged(Editable s)

改變後呼叫該方法,在Editable內部中,當text文字值改變後是呼叫該回調

public void beforeTextChanged(CharSequence s, int start, int count, int after)

該回調方法會在改變之前通知你charSequence物件會在第start位置用after長度的字元序列替換當前物件的count個數的字元

public void onTextChanged(CharSequence s, int start, int before, int count)

改變中呼叫該回調方

PhoneStateListener

監聽類,監聽手機狀態的改變。訊號強度,語音資訊等。通過TelephonyManager.Listen()給手機新增該監聽器。

Constants

LISTEN_CALL_FORWARDING_INDICATOR:來電轉駁的狀態改變

LISTEN_CALL_STATE:通話狀態的改變

LISTEN_CELL_INFO:信元資訊的改變

LISTEN_CELL_LOCATION:信元位置的改變,每隔一段時間返回一次。

LISTEN_DATA_ACTIVITY:資料連線中資料流量的方位改變

LISTEN_DATA_CONNECTION_STATE:資料連線狀態的改變

LISTEN_MESSAGE_WAITING_INDICATOR:資訊等待顯示的改變

LISTEN_NONE:停止監聽器的更新

LISTEN_SERVICE_STATE:網路服務狀態的改變

LISTEN_SIGNAL_STRENGTH:廢棄

LISTEN_SIGNAL_STRENGTHS:網路訊號強度的改變

Methods

public void onCallForwardingIndicatorChanged(boolean cfi)

來電轉駁狀態改變的回撥方法

public void onCallStateChanged(int state, String incomingNumber)

監聽通話狀態的改變的回撥方法

public void onCellInfoChanged(List<CellInfo> cellInfo)

監聽信元資訊改變的回撥方法

public void onCellLocationChanged(CellLocation location)

監聽裝置位置資訊改變的回撥方法

public void onDataActivity(int direction)

監聽資料活動狀態改變的回撥方法

public void onDataConnectionStateChanged(int state)

監聽資料連線狀態改變的回撥方法

public void onDataConnectionStateChanged(int state, int networkType)

同上,但是還監聽網路型別的改變

public void onMessageWaitingIndicatorChanged(boolean mwi)

監聽資訊等待顯示資訊改變的回撥方法

public void onServiceStateChanged(ServiceState serviceState)

監聽裝置服務狀態改變的回撥方法

public void onSignalStrengthChanged(int asu)

已廢棄

public void onSignalStrengthsChanged(SignalStrength signalStrength)

監聽訊號強度改變的回撥方法