I'm a little bit stuck with the new ContactsContract-API here. I think I don't fully understand the API and hope someone can give me a hint.
I red in the documentation that Android is aggregating several RawContacts to so called "aggregated contacts". Thats a pretty nice new feature with the 2.x Androidrelease.
What I'm not able to do is, to access this "aggregated contact". For example a user has a normal phonecontact with realname and phone saved in his phonebook and he has the same person as facebookcontact with his nickname and his birthday. Now he joins those two contacts and has his nice aggregated contact with the realname, phone and birthday which he can access.
My question: How can I as a developer access this aggregated contact?
I thought about getting all RawContacts associated with one Contact like this:
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI,
new String[]{RawContacts._ID},
RawContacts.CONTACT_ID + "=?",
new String[]{String.valueOf(contactId)}, null);
But then I would not be able to decide which name is the "real name" of the Contact and other problems. And I disliked my other hackish ideas how to aggregated those RawContacts myself, because Android with the help of the user already did this job.
Any hint how I can query those aggregated Contacts is very much appreciated!
If I understand your question correctly, ContactsContract.RawContactsEntity may help you. Check this
This problem has now been solved in this thread:
Get all contacts and their details (e.g. postal address) in one OUTER JOIN query
Related
in this question : Android get a cursor only with contacts that have an email listed >android 2.0 DArkO said that has resolved problem of listing only contacts with email. But I still can't figure out what is that filter string he used. I saw someone was asking him in comment, but without any response.
Or maybe someone else know easy way to get contacts with email?
You can query Data table set where clause to mimetype = Email.CONTENT_ITEM_TYPE and get the raw_contact_id. Then using this raw_contact_id you can get any info about this contact.
I'm trying to get all the contacts that have more than one phone number. Using sqlite3, I queried the database like this:
select number,name,person,type
from view_v1_phones
where person in
(select person from view_v1_phones group by person having count(*)>1);
and got what I was looking for. However, I don't know how I can use this when I'm querying the database using contacts api (ContactsContract).
Help!
Here is a link I found when I was working on something similar. This one is a pretty comprehensive guide to contacts in android. It is a 6-page guide! Hope this helps:
http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/1/
Google should really document their contacts API, its really irritating to find out how to insert specific details.
Anyways,
I want to send following contact details to Contact native application of android:
Name
Last Name [Family Name]
Street Address
City
State
Zip Code
Contact Phone no.
I have figured out that Family name is stored in ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME
Anyhelp will really be appreciated. And if you know any other columns insertion beyond these mentioned. I am ready to buy it. Only condition is it should use ContactsContract i.e. above android 2.1 API Level 5
Thankx :)
To set the name, your code would be like :
ConactsIntent.putExtra(ContactsContract.Intents.Insert.NAME, firstName);
Try Adding a space in between first name and the last name.
ConactsIntent.putExtra(ContactsContract.Intents.Insert.NAME, firstName+" "+lastName);
ContactsContract.CommonDataKinds.StructuredPostal.STREET
ContactsContract.CommonDataKinds.StructuredPostal.CITY
ContactsContract.CommonDataKinds.StructuredPostal.REGION
ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE
ContactsContract.CommonDataKinds.Phone.NUMBER
You'll find all of them here.
I've been reading for a couple hours now, trying to figure out how to maintain a reliable list of contacts in an Android application, but still cannot find one clear successful case.
My situation is this: I let users create Groups in my application, and in each Group, the user can select, from their contact list on the phone, which users they'd like to add to that group. I then need to be able to have a reliable way to compare a call from an incoming contact with my contacts database in my application, to see if they are in specific groups.
The easy parts are to add specific contacts to my database, and also to look up a contact based on their phone number. Thanks to this forum they are easy anyway! :) I'm storing the contacts in my database by Contact Name, Lookup Key, and Contact Id. The hard part for me, and this is what I cannot find a clear answer on, is how do I know that a month down the road, Contact X is going to have the same Lookup Key or Contact Id as when they were added? Couldn't they all change by then? Obviously the name can easily change, but can't the lookup_key and Contact ID also change? I've read about the lookup_key changing if contacts are manually aggregated. In other words, I am looking for the identifiable information for a contact that CANNOT change once they are entered?
I have read about using a ContentObserver to register for changes to the Contacts database, but I don't see that this helps me at all, since if I have Contact X with Lookup Key Y and Contact ID of Z, even if I get updated that the Contacts have changed, I still need to match Contact X in my application with Contact X in the Contacts database to update my info, which I still cannot do if the identifying information has been changed.
For example, I have a contact with Name, Lookup_Key, ContactID of Ted, 230ff392, 3209482. A month later, could it happen that what used to be Ted is now T-bone, 458ee247, 5502981? If this were the case, I cannot use these 3 identifiers as a means to look up the contact.
Thanks so much for the help on this!
Paul
I don't know where you read that the lookup key might change, but the documentation states that they are permanent in contrary to contact ids.
Contacts Provider / Contacts:
The ContactsContract.Contacts table also has the column LOOKUP_KEY
that is a "permanent" link to the contact row. Because the Contacts
Provider maintains contacts automatically, it may change a contact
row's _ID value in response to an aggregation or sync. Even If this
happens, the content URI CONTENT_LOOKUP_URI combined with contact's
LOOKUP_KEY will still point to the contact row, so you can use
LOOKUP_KEY to maintain links to "favorite" contacts, and so forth.
This column has its own format that is unrelated to the format of the
_ID column.
the account is not set , how to insert a new contact, and after inserted , the contact can be shown in the conatcts' application?
Don't know if you are still looking for answer but it might help others. Try inserting Account Name and Account Type as null, it will insert the contact and also display them in the native contact app.