其他分享
首页 > 其他分享> > android-从联系人中选择电话号码

android-从联系人中选择电话号码

作者:互联网

我对此部分表示怀疑.如何替换字符串之间的空格,何时从联系人列表中获取电话号码?
         而且工作正常,但某些android设备(例如Samsung Tab)具有
    在他们的联系人中添加空格.我从联系人那里得到号码,所以我得到了字符串99
    99 99999,而不是99999999.

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

我知道,请使用.replace()删除该空间.
 是否有其他任何过程来删除字符串之间的空格.

我附上了我的代码:::

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

解决方法:

只需替换电话号码中的每个空格

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

标签:contacts,android
来源: https://codeday.me/bug/20191025/1931451.html