2010-11-23 56 views
0

我試圖找回因此使用如何從電話號碼中檢索ID?

String addrWhere = Contacts.Phones.NUMBER + " = " + userNumber; 
    String id = ""; 
    Cursor c = mContext.getContentResolver().query(
    Contacts.Phones.CONTENT_URI, 
    new String[] { Contacts.Phones._ID }, addrWhere, null, null); 
    try { 
    if (c.getCount() > 0) { 
    c.moveToFirst(); 
    id = c.getString(0); 
    Log.i("IDS", id); 
    } 
    } finally { 
    c.close(); 
    } 
    return id; 

任何人都可以讓我知道我在這個錯誤電話號碼?

回答

0

HI每一個... 謝謝回覆! @ Sotapanna 好吧,我發現了Sotapanna指出的答案

粘貼任何需要它的人的工作代碼!

private String findID(String userNumber) { 
     Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri 
       .encode(userNumber)); 
     int id = 0; 
     String[] returnVals = new String[] { PhoneLookup._ID }; 
     Cursor pCur = mContext.getContentResolver().query(uri, returnVals, 
       PhoneLookup.NUMBER + " = \"" + userNumber + "\"", null, null); 
     if (pCur.getCount() > 0) { 
      pCur.moveToFirst(); 
      id = pCur.getColumnCount(); 
      if (id >= 0) { 
       id = pCur.getInt(0); 
      } 
     } 

     Log.i("Contacts", "" + id); 
     return String.valueOf(id); 
    } 
1

嘗試解決How to query ContactsContract.CommonDataKinds.Phone on Android?這是使用ContactsContract.PhoneLookup提供商:

Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); 
resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,... 
+0

請註明相關位,而不僅僅是一個鏈接(絕對* *包含的鏈接,但也* *引號):http://meta.stackexchange.com/questions/8231/are-answers-that- just-contain-links-elsewhere-really-good-answers – 2010-11-23 11:45:32

相關問題