开发者

Not all contacts returned

I Have tied to get all contacts by using following code

getContentResolver().query(uri, null, null, null, null)

But it doesn't retur开发者_开发知识库n all contacts. It seems that it returns only that contacts which have in column "single_is_restricted" value "1", but this column cannot be asseccable from aplication, I found it when I was viewing table "contacts" directly through sqlite.

How I can get all contacts?

Thanks.


Check the create statement for the table/view.

For example in ContactManager example you will see this code block;

private Cursor getContacts()
{
    // Run query
    Uri uri = ContactsContract.Contacts.CONTENT_URI;
    String[] projection = new String[] {
            ContactsContract.Contacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME
    };
    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
            (mShowInvisible ? "0" : "1") + "'";
    String[] selectionArgs = null;
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

    return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
}

If you can get an exception (for example you can change selection...), you can get view/table name from log cat, like this (you can see "ASDF" in log cat, just get an exception);

04-28 12:16:34.682: E/AndroidRuntime(466): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.contactmanager/com.example.android.contactmanager.ContactManager}: android.database.sqlite.SQLiteException: near "'1'": syntax error: , while compiling: SELECT _id, display_name FROM view_contacts_restricted WHERE (in_visible_group =ASDF '1') ORDER BY display_name COLLATE LOCALIZED ASC

Point is; FROM view_contacts_restricted

And now you can check this view's create statement. You can install a root browser app. And copy sqlite file to SDCARD or install sqlite3 to Android Device. then open database from command line;

sqlite3 '/home/semeteycoskun/Desktop/contacts2.db'

Check view;

.schema view_contacts_restricted

Result is;

CREATE VIEW view_contacts_restricted 
AS SELECT contacts._id AS _id
,         contacts.custom_ringtone AS custom_ringtone
,         name_raw_contact.display_name_source AS display_name_source
,         name_raw_contact.display_name AS display_name
,         name_raw_contact.display_name_alt AS display_name_alt
,         name_raw_contact.phonetic_name AS phonetic_name
,         name_raw_contact.phonetic_name_style AS phonetic_name_style
,         name_raw_contact.sort_key AS sort_key
,         name_raw_contact.sort_key_alt AS sort_key_alt
,         name_raw_contact.sort_priority AS sort_priority
,         name_raw_contact.sort_priority_alt AS sort_priority_alt
,         name_raw_contact.sort_locale AS sort_locale
,         name_raw_contact.sort_locale_alt AS sort_locale_alt
,         name_raw_contact.contact_in_visible_group AS in_visible_group
,         has_phone_number, lookup, photo_id
,         contacts.last_time_contacted AS last_time_contacted
,         contacts.send_to_voicemail AS send_to_voicemail
,         contacts.starred AS starred
,         contacts.times_contacted AS times_contacted
,         status_update_id
,         dirty_contact
,         has_email
,         link_count
,         raw_contact_linkpriority1
,         link_type1
,         raw_contact_linkpriority2
,         link_type2
,         raw_contact_linkpriority3
,         link_type3
,         raw_contact_linkpriority4
,         link_type4
,         raw_contact_linkpriority5
,         link_type5 
FROM contacts 
JOIN raw_contacts AS name_raw_contact ON(name_raw_contact_id=name_raw_contact._id) 
WHERE single_is_restricted=0;

If create statements include single_is_restricted=0 you can not access the rows that single_is_restricted=1.

[sorry for my english]


Some manufacturers like Samsung have deals with Facebook in which Facebook syncs to the device contacts with names, phones, pics, etc. but those contacts can't be accessed via the Contacts APIs.

This is the reason some contacts can't be accessed by your app, but are visible in the stock contacts app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜