Search This Blog

Sunday 24 June 2012

How to query the data from Content Provider?


The applications access the data from the other applications content providers using the content resolver object. Content Resolver runs as a client object and allow the CRUD (Create, Retrieve,Update and Delete) operations.

Content Provider Provides an abstract layer to query the data as table and hide the internal repository of application data. The Content Providers automatically handles the inter-process communication.

Note : To access the applications content provider the client application must need to specify the permissions in manifest file.

The ContentResolver object has methods identical to the ContentProvider and when resolver calls a method the identical name method will be invoked in ContentProvider Object.

The ContentResolver object ha a query method to pass a request to the ContentProvider Object.

// Queries the user dictionary and returns results
mCursor = getContentResolver().query(
    UserDictionary.Words.CONTENT_URI,   // The content URI of the words table
    mProjection,                        // The columns to return for each row
    mSelectionClause                    // Selection criteria
    mSelectionArgs,                     // Selection criteria
    mSortOrder);                        // The sort order for the returned rows
See the argument list for the query method


query() argumentSELECT keyword/parameterDescription
UriFROM table_nameUri defines the content provider table_name
projectioncol,col,col,...projection is an array of columns for select list
selectionWHERE col =valueselection specifies the filter criteria for selecting  rows.
selectionArgs
sortOrderORDER BY col,col,...sortOrder specifies the order in which rows appear in the returned Cursor.









No comments:

Post a Comment