2013-01-09 210 views
0

我正在使用以下代碼在android中使用聯繫人ID獲取聯繫人詳細信息。然而,代碼只適用於2.3.5版本的Android設備,而不是2.3.3版本或以上的版本。以下是我的代碼,其中contactId是特定聯繫人的ID。執行不進入if (phone.moveToFirst()) {}部分在Query中是否存在一些問題?如果是這樣,那麼爲什麼它在2.3.5版本上可以正常工作?任何幫助將不勝感激..謝謝從android中的contactId獲取聯繫人詳細信息?

public String queryAllPhoneNumbersForContact(int contactId) 
{ 
    String[] projection = new String[] { Phone.NUMBER, Phone.TYPE }; 

    @SuppressWarnings("deprecation") 
    Cursor phone = managedQuery(Phone.CONTENT_URI, 
      projection, 
      Data.CONTACT_ID + "=?", 
      new String[] { String.valueOf(contactId) }, null); 

    if (phone.moveToFirst()) 
    { 
     int contactNumberColumnIndex = phone.getColumnIndex(Phone.NUMBER); 
     int contactTypeColumnIndex = phone.getColumnIndex(Phone.TYPE); 

     while (!phone.isAfterLast()) 
     { 
      String number = phone.getString(contactNumberColumnIndex).trim(); 
      int type = phone.getInt(contactTypeColumnIndex); 

      System.out.println("number" + number); 
      System.out.println("Type" + getString(Phone.getTypeLabelResource(type))); 

      phone.moveToNext(); 
      if ((getString(Phone.getTypeLabelResource(type)).equals("Mobile"))) 
      { 
       Log.e("WorkNo. : ", number); 
       return number; 
      } 
     } 
    } 
    phone.close(); 
    return null; 
} 
+0

它對於早期版本不起作用嗎?另外,這是與模擬器,或設備,你試過什麼設備?最後,你有沒有試過2.2模擬器/設備? – PearsonArtPhoto

回答

0

什麼設備不工作?我推薦你使用適用於主要版本和設備的2.2版本。

+0

S5360 galaxy Y Android版本2.3.5適用於此我的意思是返回contactId使用我可以獲取其他細節。不適用於Gt-I9000版本2.3.3或甚至在版本4.0及以上。 – Joyson

相關問題