2011-07-02 3 views
0

큰 문제가 있습니다. SMS 콘텐츠 공급자와 연락처 콘텐츠 공급자간에 얻을 수있는 유일한 관계는 전화 번호이지만 SMS 콘텐츠 공급자는 숫자와 다른 형식으로 저장합니다 번호는 연락처 콘텐트 제공자에 저장된다. 따라서 어떻게 다른 관계 나 바인딩 된 열을 볼 수 없기 때문에 두 테이블 간의 수를 비교할 수 있습니다. 나는 내 나라의 전화 번호 형식이 +254728306203인데, 이것은 SMS 공급자가 전화 번호를 저장하는 방법이지만 연락처 제공 업체는 전화 번호를 072-830-6203으로 저장합니다.SMS 콘텐츠 공급자와 연락처 간의 관계

답변

0

시도해보십시오 (SDK 2.0 이상) . 숫자가 어떤 형식이든합시다. 그냥 문자열로 넘겨주세요 ...

android.permission.READ_CONTACTS을 매니페스트에 추가하십시오.

/** 
    * Retrieves display name for the provided contact number 
    * 
    * @param context 
    *   Context 
    * @param number 
    *   The contact number for which display name is to be retrieved 
    *   form android contacts 
    * @return Returns displayName for the contact if available. If display name 
    *   is not available then it returns the same number 
    */ 
    public static String getContactNameFromNumber(Context context, String number) { 
     // If name is not found, number will be returned 
     String contactDisplayName = number; 

     Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, 
       Uri.encode(number)); 
     Cursor cursor = context.getContentResolver().query(uri, 
       new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); 
     if (cursor.moveToFirst()) { 
      contactDisplayName = cursor.getString(cursor 
        .getColumnIndex(PhoneLookup.DISPLAY_NAME)); 
     } 
     cursor.close(); 
     Log.d("GetNumber", "Retrived DisplayName for contact number:" + number 
        + " DisplayName:" + contactDisplayName); 

     return contactDisplayName; 

    } 
+1

U는 천재적입니다. 코드를 사용하면 매력을 느끼게됩니다. – John

+0

Thnx John이 대답을 수락했습니다. 코드를 이해할 수 있도록이 링크를 참조하십시오. http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html – Udayan

+0

질문이 있으시면 어떻게 UR 코드의 반대를 할 수 있습니까? SMS 테이블 – John