从联系人中选择电话号码 [英] Pick Phone Number from contacts

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

问题描述

我对该部分有疑问。如何替换字符串之间的空格,何时从联系人列表中获取电话号码?
并且运行良好,但是某些android设备(例如Samsung Tab)在其联系人中添加了
空格。我从联系人那里得到号码,所以我得到的字符串是99
99 99999而不是99999999。

I have doubt in that section. How to replace space between the string, when to get phone number from Contact list? And it's working fine, But some android devices(e.g. Samsung Tab) have spaces added in their contacts. I get number from contact.So I get string 99 99 99999 instead of 99999999.

而且,如何从该号码中删除国家/地区代码。
例如:+91 999999999而不是9999999999或+020 9696854549而不是9696854549

And also, How to eliminate country code from that number. Ex: +91 999999999 instead of 9999999999 or +020 9696854549 instead of 9696854549

我知道,请使用.replace()删除该空间。

是否有其他任何过程来删除字符串之间的空格。

I know, remove that space by using .replace().
Is there any other process to remove space between the string.

我附上了我的代码:::

I attached my code:::

   public void onClick(View view) {
            Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
              startActivityForResult(contactPickerIntent, 
RESULT_PICK_CONTACT);
        }

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);

        mobile_et.setText(phoneNo);
    } catch (Exception e) {
        e.printStackTrace();
    }
}


推荐答案

替换电话号码中的每个空白

Just replace every white space in the phone number

phoneNo=phoneNo.replaceAll("\\s+","");

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

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