从联系人中选择电话号码时,如何删除国家/地区代码 [英] How to remove country code , When Pick Phone Number from contacts

查看:45
本文介绍了从联系人中选择电话号码时,如何删除国家/地区代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此部分表示怀疑.当我从联系人列表中选择电话号码时,如何删除国家/地区代码?

I have doubt in that section. How to Remove country code, when I pick phone number from contact list?

例如:+91 999999999而不是9999999999或+020 9696854549而不是9696854549请提供解决此问题的方法

Ex: +91 999999999 instead of 9999999999 or +020 9696854549 instead of 9696854549 Can any one know the answer about my question. please give solution to this problem

我在这里附加了我的代码和图像.

I attached my code and image here.

     private void contactPicked(Intent data) {
    Cursor cursor = null;
    try {
    String phoneNo = null ;
    // getData() method will have the Content Uri of the selected contact
    Uri uri = data.getData();
    //Query the content uri
    cursor = getContentResolver().query(uri, null, null, null, null);
    cursor.moveToFirst();
    // column index of the phone number
    int  phoneIndex =cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER
  phoneNo = cursor.getString(phoneIndex);
   String phoneNumber = phoneNo.replaceAll(" ","");
   mobile_et.setText(phoneNumber);
} catch (Exception e) {
    e.printStackTrace();
}
}

推荐答案

使用此功能希望对您有所帮助:

use this function hope it will help you out:

public String phoeNumberWithOutCountryCode(String phoneNumberWithCountryCode) {
        Pattern complie = Pattern.compile(" ");
        String[] phonenUmber = complie.split(phoneNumberWithCountryCode);
        Log.e("number is", phonenUmber[1]);
        return phonenUmber[1];
    }

这篇关于从联系人中选择电话号码时,如何删除国家/地区代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆