开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜