How to read contacts on Android 2.0 -
I am working on Android 2.0 and am trying to get a list of all the contacts.
android.provider.Contacts.People has been deleted, I have to use android.provider.ContactsContract , but I think it Can not find a proper example of how to use (for example: retrieve a list of all contacts on the Phonebook.) Anyone know where such an example is ? First of all, make sure you have added In your AndroidManifest.xml file, you can loop through your phone contacts like this. Additionally, you can loop through your contacts and just get the name and the phone number like this: In addition, if you need to get things like a note from a contact, you will need to use the following URIs, such as the following (to use this method Free): Note this time that I have not only used the MIME type for query but also the query ID.
& amp; ; Usage-permission Android: name = "android.permission.READ_CONTACTS" />
cursor cursor = getContentResolver () query (ContactsContract contact.contENT_URI, empty, empty, empty, empty); While (cursor.movetext ()) {string contactID = cursor.gate string (cursor.gate column index (contact contact ._id)); String isphone = cursor.get string (cursor.zstallmandindex (contactCact.CommunicationsHAS_PHONE_NUMBER)); If (Boolean.parseBoolean (hasPhone)) // // You know this is now a number so call this cursor like this query = getContentResolver (). Query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI, Null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + Contact ID, empty, empty); While (phones.moveToNext ()) {string PhoneNumber = phones.getString (phones.getColumnIndex (ContactsContract.CommonDataKinds.Phone.NUMBER)); } Phones.close (); } Cursor email = getContentResolver () query (ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + "=" + contactId, null, null). While email (emails.moveToNext ()) {// This will allow you to receive multiple email addresses String EmailAddress = emailss.getString (emails.getColumnIndex (ContactsContract.CommonDataKinds.Email.DATA)); } Emails.close (); } Cursor.close ();
Cursor people = GetContentResolver () Query (ContactsContract contact.contENT_URI, empty, empty, empty, empty); Whereas (people.moveToNext ()) {int nameFieldColumnIndex = people.getColumnIndex (PhoneLookup.DISPLAY_NAME); String contact = people.getString (nameFieldColumnIndex); Int NumberFieldColmainIndex = People. Tolkoll Index (phone lookup number); String number = people Gatestring (number field code); } People Close ();
Private string millennium (long contact ID) {string note = zero; String [] column = new string [] {ContactsContract.CommonDataKinds.Note.NOTE}; Where the string is where = contact contact Data .RAW_CONTACT_ID + "=" and "Contact + Contacts. Data MIMETYPE + "=?"; String [] where parameter = new string [] {long. Tother (Contact ID), Contact Editing CommonDayind note. CONTENT_ITEM_TYPE}; Cursor contact = getContentResolver (). Query (ContactsContract.Data.CONTENT_URI, projection, ou, ou parameter, faucet); If (contacts.moveToFirst ()) {RV = contacts.getString (0); } Contacts.close (); Return note; }
Comments
Post a Comment