In addition to the query URI manually written, you can also use the URI query constant built in Android.
For example, in addition to content: // contacts/people, you can write this assignment statement.
Uri allcontacts = contactscontract. Contacts. content_uri;
Some Android built-in predefined query string constants.
- Browser. bookmarks_uri
- Browser. searchs_uri
- Calllog. content_uri
- Mediastore. Images. mdeia. internal_content_uri
- Mediastore. Images. Media. external_content_uri
- Settings. content_uri
If you want to query the first contact, you must specify the ID.
Uri allcontacts = URI. parse ("content: // contacts/people/1 ");
You can also do this:
Uri allcontacts = contenturis. withappendedid (contactscontract. Contacts. content_uri, 1 );
In addition to displaying contacts in listview, you can also print them out.
Private void printcontacts (cursor c) {If (C. movetofirst () {do {string contactid = C. getstring (C. getcolumnindex (contactscontract. contacts. _ id); string contactdisplayname = C. getstring (C. getcolumnindex (contactscontract. contacts. display_name); log. V ("content providers", contactid + "," + contactdisplayname);} while (C. movetonext ());}}