Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

android - How to get a contact's facebook id or url from native contacts / content resolver?

How to get the facebook id or url of a contacts that's been synced to the native contacts app via Facebook sync adapter?

I went through different urls, but didn't see any info regarding facebook.

I tried

ContactsContract.Data.CONTENT_URI
ContactsContract.CommonDataKinds.Email.CONTENT_URI
ContactsContract.CommonDataKinds.Phone.CONTENT_URI
ContactsContract.Contacts.CONTENT_URI

as URIs already in the code below:

    Uri uri = ContactsContract.Data.CONTENT_URI;
    Cursor c = getContentResolver().query(uri, null, null, null, null);
    while (c.moveToNext()) {
        for (int i=0; i<c.getColumnCount(); i++) {
            Log.d(TAG, c.getColumnName(i) + ": " +  c.getString(i));
        }
        Log.d(TAG, "==================================");

    }

I do get a column value like

contact_status_res_package: com.facebook.katana

in this dump, and I also get the contacts status (contact_status column), but nowhere do I see the facebook url or id of this contact.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Got the reply from on the Google Group (http://groups.google.com/group/android-developers/browse_thread/thread/95110dd7a1e1e0b4):

Access to Facebook friends via the contacts provider is restricted to a handful of system apps by the provider itself. Other applications cannot read that data.

Therefore now I fetch an cache all contact names/id mappings via FB Graph api (http://graph.facebook.com/me/friends) and use that for the id lookup.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...