android - I'm having trouble loading email addresses from the Phone's contacts -
i trying generate list of emails phone's contacts have having trouble getting emails. can names , phone numbers not emails. arraylist sizes both 0 @ end of loop. can spot doing wrong, or tell me how emails differ phone numbers, names , other information?
contentresolver cr = getcontentresolver(); cursor emailcur = cr.query( contactscontract.commondatakinds.email.content_uri, null, contactscontract.commondatakinds.email.contact_id + " = ?", null, null); arraylist<string> emails = new arraylist<string>(); arraylist<string> emailtypes = new arraylist<string>(); while (emailcur.movetonext()) { // allow several email addresses // if email addresses stored in array string email = emailcur .getstring(emailcur .getcolumnindex(contactscontract.commondatakinds.email.data)); string emailtype = emailcur .getstring(emailcur .getcolumnindex(contactscontract.commondatakinds.email.type)); emails.add(email); emailtypes.add(emailtype); } emailcur.close(); log.i("emails count", integer.tostring(emails.size())); (int = 0; < emails.size(); i++) { log.i("emails " + i, emails.get(i)); } log.i("emailtypes count", integer.tostring(emailtypes.size())); (int = 0; < emailtypes.size(); i++) { log.i("emailtypes " + i, emailtypes.get(i)); }
use code email device.
contentresolver cr = getcontentresolver(); cur = cr.query(contactscontract.contacts.content_uri, null,null, null, null); emailindex=0; if (cur.getcount() > 0) { while (cur.movetonext()) { string id = cur.getstring(cur.getcolumnindex(contactscontract.contacts._id)); name = cur.getstring(cur.getcolumnindex(contactscontract.contacts.display_name)); cursor emails = getcontentresolver().query(contactscontract.commondatakinds.email.content_uri,null, contactscontract.commondatakinds.email.contact_id+ " = " + id, null, null); while (emails.movetonext()) { // allow several email addresses string emailaddress = emails.getstring(emails.getcolumnindex(contactscontract.commondatakinds.email.data)); log.v(name+"==>", emailaddress); } emails.close(); } cur.close();
Comments
Post a Comment