나와 연락처 이름을 갖고 있고 전화 번호를 원합니다. Android에서 해당 이름의 연락 전화 번호를 얻는 방법은 무엇입니까?android의 연락처 이름에서 연락 전화 번호를 얻는 방법
답변
연락처 이름의 표시 이름과 연락처에 대한 모든 휴대 전화 번호를 로그 캣하기 위해 다음 코드는 로그 아웃됩니다이 코드
people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, "person_name"+"='"+name+"'", null, null);
people.moveToFirst();
{
{
try{
String contactId = people.getString(people.getColumnIndex(ContactsContract.Contacts._ID));
String hasPhone = people.getString(people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone.equalsIgnoreCase("1"))
hasPhone = "true";
else
hasPhone = "false" ;
if (Boolean.parseBoolean(hasPhone))
{
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
while (phones.moveToNext())
{
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
mConno.add(position,phoneNumber);
}
phones.close();
}
if(hasPhone=="false")
{ mConname.remove(position);
}
else
position++;
}
catch(Exception e)
{
}
}
}
을 시도해보십시오
Cursor cursor = null;
try {
cursor = getContentResolver().query(Data.CONTENT_URI,
new String [] { Data.RAW_CONTACT_ID },
StructuredName.DISPLAY_NAME + "=? AND "
+ Data.MIMETYPE + "='" + StructuredName.CONTENT_ITEM_TYPE + "'",
new String[] { contactName}, null);
if (cursor != null && cursor.moveToFirst()) {
do {
String rawContactId = cursor.getString(0);
Cursor phoneCursor = null;
try {
phoneCursor = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Phone.NUMBER},
Data.RAW_CONTACT_ID + "=?" + " AND "
+ Phone.TYPE + "=" + Phone.TYPE_MOBILE + " AND "
+ Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
new String[] {rawContactId}, null);
if (phoneCursor != null && phoneCursor.moveToFirst()) {
String number = phoneCursor.getString(phoneCursor.getColumnIndex(Phone.NUMBER));
Log.d(TAG, "Mobile Number: " + number);
}
} finally {
if (phoneCursor != null) {
phoneCursor.close();
}
}
} while (cursor.moveToNext());
}
} finally {
if (cursor != null) {
cursor.close();
}
}
안녕하세요, 비슷한 시도했지만 작동하지 않았다. 여기에 내 질문이있다, 나는 정말로 당신의 도움에 감사 할 것입니다! :) http://stackoverflow.com/questions/35097844/get-contact-name/35098111#35098111 –
짧은 버전; 해당 권한이 필요합니다 (android.permission.READ_CONTACTS)
public String getPhoneNumber(String name, Context context) {
String ret = null;
String selection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME+" like'%" + name +"%'";
String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor c = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
projection, selection, null, null);
if (c.moveToFirst()) {
ret = c.getString(0);
}
c.close();
if(ret==null)
ret = "Unsaved";
return ret;
}
내 메인 활동에서 이것을 어떻게 호출합니까? – Si8
문자열 번호 = getPhoneNumber (contactName, MainActivity.this); –
- 1. J2ME에서 연락 전화 번호를 얻는 방법은 무엇입니까?
- 2. 연락처 전화 번호 검색 Android의 URI에서
- 3. 자신의 전화 번호를 얻는 방법?
- 4. 안드로이드에서 전화 번호를 얻는 방법
- 5. 안드로이드에서 전화 번호를 얻는 방법
- 6. 전화 번호를 기반으로 연락처 정보를 쿼리하는 방법
- 7. 는 얻기 연락 전화 번호
- 8. 갱신 연락처 전화 번호
- 9. Palm WebOS - 사용자의 전화 번호를 얻는 방법?
- 10. 실제 장치에서 전화 번호를 얻는 방법
- 11. 연락처에서 선택된 사람의 전화 번호를 얻는 방법
- 12. 안드로이드에서 나가는 전화 번호를 얻는 방법?
- 13. 아이폰에서 내 전화 번호를 얻는 방법
- 14. iPhone에서 MKReverseGeocoder를 사용하여 주소 및 전화 번호를 얻는 방법
- 15. android의 특정 연락처 삭제
- 16. 그 사람의 전화 번호로 연락처 이름을 얻는 방법
- 17. 전화 번호를 캡처하는 방법
- 18. 등록을 청취하는 방법 android의 연락처 변경
- 19. 고객 전화 번호를 받으십시오.
- 20. Android를 사용하여 연락처 번호를 읽는 방법
- 21. Magento : 매장 연락처 전화
- 22. 내가 연락처 이름과 전화 번호를 업데이트하고 안드로이드 연락처를
- 23. 연락처 전화 번호 받기
- 24. iPhone 주소록 : 전화 번호가있는 연락처 목록을 얻는 방법?
- 25. 전화 번호를 지오 코딩하는 방법
- 26. 페이스 북 연락처를 읽을 때 전화 번호를 얻는 방법
- 27. 안드로이드 프로그래밍에서 내 연락처에서 전화 번호를 얻는 방법
- 28. Facebook API - 사용자의 주소, 전화 번호를 얻는 방법은 무엇입니까?
- 29. SKU 번호를 얻는 방법
- 30. odbcexception 번호를 얻는 방법
다음은 유용한 링크입니다. http://stackoverflow.com/questions/2356084/read-all-contacts-phone-numbers-in-android http://stackoverflow.com/questions/866769/how-to-call-android-contacts-list –