2013-07-07 86 views
2

我希望根據一組電話號碼檢索聯繫人列表。這裏出了什麼問題?從一組電話號碼中檢索聯繫人

目前正在使用此 -

private String numbers = "'12345', '54321'"; 

String[] mSelectionArgs = {numbers};' 

return new CursorLoader(getActivity(), 
        PhoneLookup.CONTENT_FILTER_URI, 
        ContactsQuery.PROJECTION, 
        ContactsQuery.SELECTION, 
        mSelectionArgs, 
        PhoneLookup.DISPLAY_NAME); 

投影和選擇都是在ContactsQuery定義如下

final static String[] PROJECTION = { 
     PhoneLookup._ID, 

     PhoneLookup.LOOKUP_KEY, 

      PhoneLookup.DISPLAY_NAME, 

      PhoneLookup.PHOTO_THUMBNAIL_URI, 

    }; 

final static String SELECTION =  
      PhoneLookup.HAS_PHONE_NUMBER + "=1 AND " + PhoneLookup.NUMBER) + " IN (?)"; 

但是,我得到的錯誤:

07-08 00:44:21.007 :E/AndroidRuntime(2307):引起:java.lang.IllegalArgumentException:URI:content://com.android.contacts/phone_lookup,調用user:com.example.android.contactslist,調用package:com.exa mple.android.contactslist

回答

0

嘗試:

ContentResolver的CR = context.getContentResolver(); Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,null,(DISPLAY_NAME ='「+ name +」'「),null,null);

+0

Contacts.CONTENT_URI將不允許我基於PhoneNumbers進行過濾。因此使用PhoneLookup.CONTENT_FILTER_URI –

相關問題