1

버튼 클릭시 연락처 전화 번호를 클릭 한 다음 EditText로 전송할 수 있지만 국가 코드없이 결과 만 받고 싶습니다. 예 : +33 xx xx xx xxx becomes xx xx xx xxx연락처에서 번호 선택하기 국가 코드 제거

내가이 방법을 사용할 수 있습니까?

버튼 클릭 :

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

답변

0

봅니다 완전히 대체를 사용하는 다음 코드는 내가 번호를하고 글고 치기에 넣어 사용합니다. 예 : String phone = cursor.getString(0); phone = phone.replaceAll("+33", ""); editText.setText(phone);

+0

답변 주셔서 감사합니다. 그러나 작동하지 않습니다. –

1

Google의 libphonenumber 라이브러리를 사용하십시오. 형식이 위치에 따라 다르므로 자신의 논리를 만들려고 시도하지 마십시오.

+0

내 사례와 일치하는 코드가있는 예는 무엇입니까? –