what is the meaning of suggestions in a Content Provider Uri? - android

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.

Related

Storing and retrieving contact info from ContactsContract

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.

How does the content provider uri work?

I've been researching ContentProviders for a while now and I'm still having trouble grasping how exactly the Uri works.
content://app_name/path/id
When a path is specified how does the table corresponding to that path gets accessed?
It seems like you would need to label the table with that path. Is it so?
You are right google docs on this point are not very clear :
First : you must define an authority for a custom provider :
http://developer.android.com/guide/topics/providers/content-provider-creating.html#ContentURI
<provider
android:name=".ProviderDemo"
android:authorities="com.foo.android.providerdemo" />
Second : use this authority when you query a provider :
http://developer.android.com/guide/topics/providers/content-provider-creating.html#ContentURI
//query all items
getContentResolver().query("content://com.foo.android.providerdemo/",...)
//query a single item
getContentResolver().query("content://com.foo.android.providerdemo/idOfItem>",...)
//query a view
getContentResolver().query("content://com.foo.android.providerdemo/<idOfView>/",...)
To help you choose which action to take for an incoming content URI, the provider API includes the convenience class UriMatcher, which maps content URI "patterns" to integer values. You can use the integer values in a switch statement that chooses the desired action for the content URI or URIs that match a particular pattern.
My confusion came from a lack of SQLite knowledge. I was unaware that a database holds many tables and not just 1 table. Now I realize that the authority of the Uri must take you to the database and then the path will take you to the correct table.

SearchManager - adding custom suggestions

I've read all of the documentation online about building search interfaces and adding custom suggestions... but I'm still unclear on how this works. The documentation says that I must "Build a table (such as in an SQLiteDatabase) for your suggestions and format the table with required columns". I'm assuming the system will eventually fill this table with the appropriate suggestions on its own... but which process/class is responsible for this, and when will the actual insertions occur (before any query is made by the user, after a query has been made by the user, etc.)?
And while I'm asking a question up here, if someone could clarify the difference between an AutoCompleteTextView and a SearchView w/ custom suggestions... that'd be awesome. AutoCompleteTextView seems suspiciously easy to implement compared to the SearchView (which requires changes to be made to the ContentProvider, SQLiteDatabase helper class, etc.).
You have to create a content provider which delivers your custom suggestions based on a query so far entered in the search view. In your searchable.xml you configure the minimum length of the search expression, which must be reached before asking for suggestions. This content provider is called a suggestion provider (it still extends ContentProvider). The content provider's authority is also configured in searchable.xml.
There is no limitation on how the suggestion provider computes its suggestions. You can search the web query a database or read a file. But the answer to the query is in the format of a table. If the suggestions is directly queried from a database you can use the cursor answered by the database query to deliver the result in the content provider's query() method. If the result is computed from one or more sources you can create a table on the fly by using a MatrixCursor.
The rows of the answer from the suggestion provider are used by the search mechanism to display the suggestion, they are stored in a table. The format of the rows is as follows:
private static final String[] COLUMNS = {
"_id",
SearchManager.SUGGEST_COLUMN_ICON_1, // ID of a drawable (icon) as String
SearchManager.SUGGEST_COLUMN_TEXT_1, // main text for suggestion display
SearchManager.SUGGEST_COLUMN_TEXT_2, // secondary text for suggestion display
SearchManager.SUGGEST_COLUMN_INTENT_DATA, // this could be an URI to access the suggestion as used in an intent with a VIEW action
SearchManager.SUGGEST_COLUMN_INTENT_ACTION, // this could be Intent.ACTION_VIEW
SearchManager.SUGGEST_COLUMN_SHORTCUT_ID // e.g. SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT
};
Searching is described here in more detail: http://developer.android.com/guide/topics/search/index.html

how to display suggestions from the web

I overwite the SearchRecentSuggestionsProvider to make the custom suggestions for my search, but now I need to return the suggestion data from the server instead of the local provider, how to solve it?
Well, I would say that it is not a good practice but it can be done.
Basically you need to:
- override the method query in your content provider
- query your server or whatever for getting the results
- building a cursor out of the results using a MatrixCursor
From the doc:
If your search suggestions are not stored in a table format (such as an SQLite table)
using the columns required by the system, then you can search your suggestion data for
matches and then format them into the necessary table on each request. To do so, create
a MatrixCursor using the required column names and then add a row for each suggestion
usingaddRow(Object[]). Return the final product from your Content Provider's query()
method.
Hope it will help.

Content Provider filtering query, filtering Cursor

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.

Categories

Resources