我可以通过单击按钮获取联系电话号码,然后将其传输到 EditText,但我只想获得没有国家代码的结果。示例:+33 xx xx xx xxx becomes xx xx xx xxx
有没有办法可以做到这一点?我使用以下代码获取数字并将其放入 EditText:
按钮点击:
Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
intent.setType(CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, 1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == 1) && (resultCode == RESULT_OK)) {
Cursor cursor = null;
try {
Uri uri = data.getData();
cursor = getContentResolver().query(uri, new String[] { CommonDataKinds.Phone.NUMBER }, null, null, null);
if (cursor != null && cursor.moveToNext()) {
String phone = cursor.getString(0);
editText.setText(phone);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}