I have 3 email's of the same contact. I need to update this emails to phone book of Android. The problem is that when I try do this, the 3 email's are updated the same way. The 3 email's stay equals. Exist any way to distinguish the emails?
Here is my code
if(numEmails>1){
int auxNumEmails=1;
String tagEtEmail = "ete";
String tagBtnLabelEmail = "btnLabelMail";
//Determinar o número de email do content
do{
EditText etEmail = (EditText)contentEmail.findViewWithTag(tagEtEmail);
Button etBtnLabelEmail = (Button)contentEmail.findViewWithTag(tagBtnLabelEmail);
String stEtEmail = etEmail.getText().toString();
String stBtnLabelEmail = etBtnLabelEmail.getText().toString();
values.clear();
String mailWhere = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?" + ContactsContract.CommonDataKinds.Email.DATA+"=?";
String[] mailWhereParams = new String[]{String.valueOf(idContacto),ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, "2"};
values.put(ContactsContract.CommonDataKinds.Email.DATA,stEtEmail);
if(stBtnLabelEmail == "Residência"){
values.put(ContactsContract.CommonDataKinds.Email.TYPE,ContactsContract.CommonDataKinds.Email.TYPE_HOME);
values.put(ContactsContract.CommonDataKinds.Email.LABEL,stBtnLabelEmail);
}
else
if(stBtnLabelEmail == "Emprego"){
values.put(ContactsContract.CommonDataKinds.Email.TYPE,ContactsContract.CommonDataKinds.Email.TYPE_WORK);
values.put(ContactsContract.CommonDataKinds.Email.LABEL,stBtnLabelEmail);
}
**cr.update(ContactsContract.Data.CONTENT_URI, values, mailWhere, mailWhereParams);**
tagEtEmail = "ete"+auxNumEmails;
tagBtnLabelEmail = "btnLabelMail" + auxNumEmails;
auxNumEmails++;
}while(auxNumEmails<=numEmails);
I need a way to distinguish the emails. Id? But how?
The solution that i use to distinguish diferent emails for the same contact is use the tag atribute. Each email have a diferent tag that allow distinguish each one.