I need to update the Label email address on phone book of android. Anyone know how i can do this?
Here is my code
String stEtEmail = etEmail.getText().toString(); //EMAIL
String stBtnLabelEmail = etBtnLabelEmail.getText().toString(); //**LABEL**
values.clear();
String mailWhere = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?";
String[] mailWhereParams = new String[]{String.valueOf(idContacto),ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE};
values.put(ContactsContract.CommonDataKinds.Email.DATA,stEtEmail);
cr.update(ContactsContract.Data.CONTENT_URI, values, mailWhere, mailWhereParams);
I don't know how i can update the my label of email.
I have get the solution:
values.put(ContactsContract.CommonDataKinds.Email.TYPE,ContactsContract.CommonDataKinds.Email.TYPE_HOME); //TYPE_WORK TYPE_HOME.......
values.put(ContactsContract.CommonDataKinds.Email.LABEL,stBtnLabelEmail);
Related
I'm using the below code:
int indexContactId = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID);
/*......*/
int id = Integer.parseInt(people.getString(indexContactId));
Cursor name_cursor = ctx.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, ContactsContract.Data.CONTACT_ID + " = " + id, null, null);
String first_name = "";
String last_name = "";
while (name_cursor.moveToNext()) {
if (name_cursor.getString(name_cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME)) != null) {
first_name = name_cursor.getString(name_cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
last_name = name_cursor.getString(name_cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
}
}
name_cursor.close();
to get the first and last name of the contact (separately).
Alongside this, I'm also retrieving the DISPLAY_NAME
int indexName = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
The problem is that for some of the contacts, I get values like:
DISPLAY_NAME: Franck MILEN
FAMILY_NAME: 0
GIVEN_NAME: Skype video
call
What's going on with the Skype call thing ? And how can I retrieve the proper MILEN name ? Or at least know to ignore these, as Franck MILEN is also returned with proper names.
EDIT
What I need is a better way to get the first_name, last_name, and phone_number of a user (first and last name should be separate) and not get or ignore the Skype video call things :)
Seems I need to answer my own question. Here's the code I'm using, and it seems to work, it doesn't return the Skype contacts anymore:
int id = Integer.parseInt(people.getString(indexContactId));
String[] projectionNames = new String[]{ContactsContract.Data.DATA2, ContactsContract.Data.DATA3};
String where = ContactsContract.Data.CONTACT_ID + " = " + id
+ " AND "
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'";
Uri uriNames = ContactsContract.Data.CONTENT_URI;
Cursor name_cursor = ctx.getContentResolver().query(uriNames, projectionNames, where, null, null);
String first_name = "";
String last_name = "";
while (name_cursor.moveToNext()) {
first_name = name_cursor.getString(name_cursor.getColumnIndex(ContactsContract.Data.DATA2));
last_name = name_cursor.getString(name_cursor.getColumnIndex(ContactsContract.Data.DATA3));
}
name_cursor.close();
name_cursor = null;
I am using this code to get phone contacts. I am getting multiple names based on how many mobile/work numbers I have entered . I basically want only one contact id with last edited/added mobile number .Is there a way I can edit the following query to achieve that result ? I really appreciate any help.
Cursor cur = managedQuery(ContactsContract.Data.CONTENT_URI, null, ContactsContract.Contacts.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'", null,
ContactsContract.Data.DISPLAY_NAME + " ASC");
int number = mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int name = mCursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME);
while (mCursor.moveToNext()) {
String phName = mCursor.getString(name);
String phNumber = mCursor.getString(number);
String thumbnailUri = mCursor.getString(mCursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI));
}
try using the modified date
Cursor cur = managedQuery(ContactsContract.Data.CONTENT_URI, null, ContactsContract.Contacts.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'", null, ContactsContract.Data.CONTACT_LAST_UPDATED_TIMESTAMP + " DESC");
int _id = mCursor.getColumnIndex(ContactsContract.Data.CONTACT_ID);
int number = mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int name = mCursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME);
while (mCursor.moveToNext()) {
int id = mCursor.getString(_id);
String phName = mCursor.getString(name);
String phNumber = mCursor.getString(number);
String thumbnailUri = mCursor.getString(mCursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI));
}
check you queue. If your id are same for similar name contacts then group them. Let me know after trying this
I have a string content//com.android.contacts/contacts/contacts/2 ie aft the user has selected a particular number.
From this string, how do i get the phone number of this particular contact?
I am new to android environment, so my question might seem a bit primitive.
Cursor c = (Cursor)mAdapter.getItem(a.keyAt(i));
Long id = c.getLong(c.getColumnIndex(ContactsContract.Contacts._ID));
contacts.add(ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id));
chosenContacts = sb.toString();
chosenContacts is my string and that contains content//com.android.contacts/contacts/contacts/2
You need a second request. You can use the id of your snippet for it:
Cursor phoneNoCursor = contentResolver.query(
Data.CONTENT_URI,
new String[] {Phone.NUMBER, Phone.TYPE, Phone.LABEL},
Data.MIMETYPE + " = ? AND " + Data.CONTACT_ID + " = ? ",
new String[] {String.valueOf(Phone.CONTENT_ITEM_TYPE, id)},
null);
For the list of possible types see the description of the Phone class. But maybe the number itself and its label are enough anyway.
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.
Anyone knows how I can update two emails in phone book of android with same TYPE
(for example: TYPE_HOME), but update each mail with a different string.
In my way I update the emails, but the emails that have the same TYPE, are updated simultaneously with the same string and i don't want this.
What I want
Email_1->TYPE_HOME->String_Hello
Email_2->TYPE_HOME->String_Hello_again
Different string but the same type.
Here is my code
EditText etEmail = (EditText)contentEmail.findViewWithTag("ete1");
String stEtEmail = etEmail.getText().toString();
values.clear();
Log.w(SocioEdit.class.getName(), "TESTE DO TYPE" +String.valueOf(ContactsContract.CommonDataKinds.Email.TYPE).charAt(3));
String mailWhere = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=? AND " + String.valueOf(ContactsContract.CommonDataKinds.Email.TYPE) + "= ?";
String[] mailWhereParams = new String[]{String.valueOf(idContacto),ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,String.valueOf(ContactsContract.CommonDataKinds.Email.TYPE_HOME)};
values.put(ContactsContract.CommonDataKinds.Email.DATA,stEtEmail);
Log.w(SocioEdit.class.getName(),"TESTE DA STRING DO EMAIL-->" +stEtEmail);
cr.update(ContactsContract.Data.CONTENT_URI,values, mailWhere, mailWhereParams);
}
As we know that Email has a stored in Data table,
So it has its id and we can get the data ID as well as Email type and Email information
so if we get the email Id in data table
we can do it like this:
cr.update(ContactsContract.Data.CONTENT_URI,values, Data.id+"=?", new String[]{String.valueOf(ID)});