[android] android framework中的 PhoneNumberUtils 类详解

 

 

PhoneNumberUtils.java (frameworks\base\telephony\java\android\telephony)

 

package android.telephony;

import com.android.i18n.phonenumbers.NumberParseException;
import com.android.i18n.phonenumbers.PhoneNumberUtil;
import com.android.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber;
import com.android.i18n.phonenumbers.ShortNumberUtil;
import com.android.i18n.phonenumbers.Phonemetadata.PhoneMetadata;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.location.CountryDetector;
import android.net.Uri;
import android.os.SystemProperties;
import android.provider.Contacts;
import android.provider.ContactsContract;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseIntArray;

import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY;
import static com.android.internal.telephony.TelephonyProperties.PROPERTY_IDP_STRING;
import static com.android.internal.telephony.TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/// M : [mtk04070][111116][ALPS00093395]Use Gemini object @{
import static com.android.internal.telephony.PhoneConstants.GEMINI_SIM_1;
import static com.android.internal.telephony.PhoneConstants.GEMINI_DEFAULT_SIM_PROP;
import static com.android.internal.telephony.PhoneConstants.GEMINI_SIM_ID_KEY;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import com.mediatek.common.featureoption.FeatureOption;
import com.mediatek.common.MediatekClassFactory;
import com.mediatek.common.telephony.IPhoneNumberExt;
import com.android.internal.telephony.PhoneConstants;
/// @}

import android.os.ServiceManager;
import com.android.internal.telephony.ITelephony;


/**
 * Various utilities for dealing with phone number strings.
 */
public class PhoneNumberUtils

 

 

 

 

   /**
     * Returns the last numDigits of the reversed phone number
     * Returns null if np == null
     */
    private static String
    internalGetStrippedReversed(String np, int numDigits) {
        if (np == null) return null;

        StringBuilder ret = new StringBuilder(numDigits);
        int length = np.length();

        for (int i = length - 1, s = length
            ; i >= 0 && (s - i) <= numDigits ; i--
        ) {
            char c = np.charAt(i);

            ret.append(c);
        }

        return ret.toString();
    }

    /**
     * Basically: makes sure there's a + in front of a
     * TOA_International number
     *
     * Returns null if s == null
     */
    public static String
    stringFromStringAndTOA(String s, int TOA) {
        if (s == null) return null;

        if (TOA == TOA_International && s.length() > 0 && s.charAt(0) != '+') {
            return "+" + s;
        }

        return s;
    }

    /**
     * Returns the TOA for the given dial string
     * Basically, returns TOA_International if there's a + prefix
     */

    public static int
    toaFromString(String s) {
        if (s != null && s.length() > 0 && s.charAt(0) == '+') {
            return TOA_International;
        }

        return TOA_Unknown;
    }

    /**
     *  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)"
     *
     * @param bytes the data buffer
     * @param offset should point to the TOA (aka. TON/NPI) octet after the length byte
     * @param length is the number of bytes including TOA byte
     *                and must be at least 2
     *
     * @return partial string on invalid decode
     *
     * FIXME(mkf) support alphanumeric address type
     *  currently implemented in SMSMessage.getAddress()
     */
    public static String    calle

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
这是一个自己开发的Android 直接发送短信方法附上代码,Android 发短信功能,包括了对内容合法性的验证,发送完成弹出提示。自己开发的直接发送短信的方法:   private void sendSMS(String telNo,String smsStr,View v){    PendingIntent pi=    PendingIntent.getActivity(this, 0, new Intent(this,Sample_11_1.class), 0);    SmsManager sms=SmsManager.getDefault();    sms.sendTextMessage(telNo, null, smsStr, pi, null);    //短信发送成功给予提示    Toast.makeText(    Sample_11_1.this, //上下文    "恭喜你,短信发送成功!", //提示内容    5000 //信息显示时间    ).show();    v.setEnabled(true);//短信发送完成后恢复发送按钮的可用状态   }   对手机号码和短信内容的验证部分:   //获取输入的电话号码   EditText etTel=(EditText)findViewById(R.id.EditText02);   String telStr=etTel.getText().toString();   //获取输入的短信内容   EditText etSms=(EditText)findViewById(R.id.EditText01);   String smsStr=etSms.getText().toString();   //判断号码字符串是否合法   if(PhoneNumberUtils.isGlobalPhoneNumber(telStr)){//合法则发送短信    v.setEnabled(false);//短信发送完成前将发送按钮设置为不可用    sendSMS(telStr,smsStr,v);   }   else{//不合法则提示    Toast.makeText(    Sample_11_1.this, //上下文    "电话号码不符合格式!!!", //提示内容    5000//信息显示时间    ).show();   }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值