开发者

How to query Contacts that have both a phone number and name?

开发者 https://www.devze.com 2023-01-25 07:30 出处:网络
I have following code in pre-Android2.0 API: String[] PROJECTION = new String[] { Contacts.People._ID, Contacts.PeopleColumns.NAME, Contacts.Phones.NUMBER };

I have following code in pre-Android2.0 API:

    String[] PROJECTION = new String[] { Contacts.People._ID, Contacts.PeopleColumns.NAME, Contacts.Phones.NUMBER };
    Cursor c = mActivity.managedQuery(Cont开发者_开发知识库acts.People.CONTENT_URI, PROJECTION, null, null, Contacts.People.DEFAULT_SORT_ORDER);

What kind of selection should I do to retrieve contacts that have both name and phone number?


In Android 1.6 and older:

String[] PROJECTION=new String[] {  Contacts.Phones._ID,
                                    Contacts.Phones.NAME,
                                    Contacts.Phones.NUMBER
                                    };
Cursor c=a.managedQuery(Contacts.Phones.CONTENT_URI, PROJECTION, null, null, null);

In Android 2.0 and newer:

String[] PROJECTION=new String[] {  Contacts._ID,
                                    Contacts.DISPLAY_NAME,
                                    Phone.NUMBER
                                    };
Cursor c=a.managedQuery(Phone.CONTENT_URI, PROJECTION, null, null, null);

Here is a sample project demonstrating their use, including detecting and using the proper API based on device OS level.

0

精彩评论

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