So, I can write to and retrieve info from the ContactsContract, however I have a question about how it works.
It is my understanding that all contact information for Contacts are stored within ContactsContract.Contact and ContactsContract.Data (ContactsContract.CommonDataDataKinds.Phone/Email/etc are all references to ContactsContract.Data, right?). A majority of this info is stored within ContactsContract.Data.DATA1-15.
Ignoring contact groups, if I wanted to create a contact app, do I only need to worry about DATA1-DATA15 for storing actual numbers/email/address/birthday/etc? What happens if a contact has more than 14 pieces of contact data (DATA15 is a blob)?
Am I missing something vital?
Edit - I'm looking more into it, and it seems like the common MIME types may be the best way of searching. If I search the following MIMETYPES:
StructuredName.CONTENT_ITEM_TYPE
Phone.CONTENT_ITEM_TYPE
Email.CONTENT_ITEM_TYPE
Photo.CONTENT_ITEM_TYPE
Organization.CONTENT_ITEM_TYPE
Im.CONTENT_ITEM_TYPE
Nickname.CONTENT_ITEM_TYPE
Note.CONTENT_ITEM_TYPE
StructuredPostal.CONTENT_ITEM_TYPE
GroupMembership.CONTENT_ITEM_TYPE
Website.CONTENT_ITEM_TYPE
Event.CONTENT_ITEM_TYPE
Relation.CONTENT_ITEM_TYPE
SipAddress.CONTENT_ITEM_TYPE
Will that handle everything? It's probably important to note that I'm using ContactsContract.Contacts.CONTENT_FILTER_URI as my search query. My goal is to have a similar effect as the standard app, where if I search, I can display the matching field below the contact's name.
Thanks for the help.
Related
I want to search the contact list to get a particular contact using _ID or LOOKUP_KEY. Which one of these two is better and the reason. It will be really helpful if you give the main differences of both.
Android Doc says-
_ID - Row ID. Consider using LOOKUP_KEY instead.
LOOKUP_KEY - An opaque value that contains hints on how to find the contact if its row id changed as a result of a sync or aggregation.
So when in case the contacts RowID change for any reason LOOKUP_KEY is our way to go. Check this link on how to find it as this is not there on Docs I guess.
WHAT I WANT TO ACHIEVE
=> Create an ANDROID app that shows the list of car manufacturers and the type of models they make. So when the user opens the app they see list of manufacturers. (ALL THIS DATA WILL BE LOADED FROM A DATABASE)
Like
1.Toyota
2.GMC etc..
So when they click on Toyota they will see the different cars Toyota makes (BY LOADING THEM FROM DATABASES). There would be sequence of screens displaying the different models .
SCREEN 1: Toyota Camry[A PICTURE , LITTLE DETAIL , AND A (VIDEO OR AUDIO) ]
SCREEN 2: Toyota Carina II[SAME THING HERE, (VIDEO OR AUDIO) , PICTURE AND DETAILS ABOUT CAR] etc...
So in each SCREEN there would be some kind of media related to THE CAR MODEL as shown above. A video or an audio promoting the car and some kind of text related to that model.
Now I'm downloading this information and want to save this kind of information of manufacturers and their cars in a database . I just cant come up with a good DB schema that let me safe this kind of data and let me load back to the screens .
--> If you can give me a general database schema like the number of tables I should have etc.. i would really appreciate.
SCHEMA I THOUGHT OF BUT DOESN'T LOOK GOOD
==>MANUFACTURERS TABLE[*MANUFACTURERS _ID , COMPANY_NAME , *MODELS ???HERE WHAT AM I MISSING ??? **]
==>MODELS_TABLE [*MANUFACTURERS _ID , MODEL_ID ,MODEL_NAME*]
==>RELATED MEDIA [*MODEL_ID , VIDEO_LOCATION , AUDIO_LOCATION , DETAILS_ABOUT_THE_CAR*]
AS YOU SEE AM JUST NOT GOOD WITH THE DESIGN :/ SO PLEASE HELP , THANKS IN ADVANCE
Any answer to this might be slightly subjective but my personal approach would be as follows...
Two tables called MANUFACTURERS and MODELS.
For the MANUFACTURERS table I'd have the following columns...
_id, company_name
For the MODELS table I'd have the following columns...
_id, manufacturer_id, model_name, description, video_uri, audio_uri
I've used _id for both tables as an Android Cursor needs a column called _id when used with Adapters. Create _id as UNIQUE PRIMARY KEY.
I also don't think it is necessary to have a separate table for the media as it relates directly to each model of car and the data can be included directly in the MODELS table.
I've used description as a generic term instead of DETAILS_OF_CAR and used _uri for the video and audio as it implies the media may be either stored locally or on a network server.
Other people might take a different approach but from what you describe this is the way I would do things.
I've got a Uri as below: content://com.android.contacts/contacts/#/suggestions
What data will it return? What's the meaning of 'suggestions' here?
Thanks in advance!
The Contacts API references the ContactsContract helper classes for dealing with contacts. "suggestions" is the string identifying the AggregationSuggestions sub-table (note the constant called CONTENT_DIRECTORY), which is used to provide information about how RawContacts that appear to describe the same person are aggregated into a single Contact.
I'm building an app where I need the user to select some "favorite" contacts and a phone number. I'm able to select a contact using
startActivityForResult(new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI), PICK_CONTACT_REQUEST);
and I'm able to extract all the information I need.
I then proceed to save the _id of the contact into my own database. My plan is to later list all the "favorited" contacts and display the name and phonenumber in a listview.
I want to save the contact id instead of the name and number so my listview will reflect any changes the user makes to his or her contacts.
But now I'm stuck. I don't know how to transform my table with contacts ids into a table with contact names.
I would like to something like this
my_table LEFT OUTER JOIN contacts_table ON (my_table.contact_id = contacts_table._id)
What you will want to do here is to store those IDs then when you want to pull the names from the user's address book, you'll have to cross reference the IDs with the contacts intent you have store in order to filter them out.
Basically you cant join a non-existent table (contacts_table).
You could probably just save the contect IDs however you wish, and then loop through the contact IDs and look up the contacts one-by-one extracting the data you need. If that's quick enough you wouldn't need any SQL joins ("optimize by need").
Perhaps its even quicker to use some Google API and use HTTP/XML to fetch the contacts (perhaps cache them for a while as well).
I got following problem, I need to use a Content Provider to read a
Database of an other App.
first I want all rows, and after analyzing the data only e.g. the rows
from _id = 1, 3 and 5.
how can I call a Content provider and select only these rows?
or is it possible to create a subset Cursor form an given Cursor?
Thanks in advance.
If you're talking to another app, I assume you're querying the other app's ContentProvider to get the data from them in the first place.
In this situation, the cleanest answer seems not to build your own ContentProvider that filters/wraps theirs. Instead query their ContentProvider from your application directly, and use the select clause in your query() to specify the conditions that define the subset of data you want to be given.