↳
android.content.ContentResolver
Known Direct Subclasses
A mock ContentResolver
class that isolates the test code from the real content
system.
Class Overview
This class provides applications access to the content model.
Summary
Public Constructors
Public Methods
final int
Inserts multiple rows into a table at the given
URL.
final int
Uri url, String where, String[]
selectionArgs)
Deletes row(s) specified by a content
URI.
Return the MIME type of the given content
URL.
final Uri
Inserts a row into a table at the given
URL.
void
Notify registered observers that a row was
updated.
void
Uri uri, ContentObserver
observer, boolean syncToNetwork)
Notify registered observers that a row was
updated.
Open a raw file descriptor to access data under a
"content:" URI.
Open a raw file descriptor to access data under a
"content:" URI.
Open a stream on to the content associated with a content
URI.
Open a stream on to the content associated with a content
URI.
Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Query the given URI, returning a Cursor over the
result set.
final void
Uri uri, boolean
notifyForDescendents, ContentObserver
observer)
Register an observer class that gets callbacks when data
identified by a given content URI changes.
void
Start an asynchronous sync operation.
final void
Unregisters a change observer.
final int
Update row(s) in a content URI.
static void
Check that only values of the following types are in the
Bundle:
Integer
Long
Boolean
Float
Double
String
null
[Expand]
Inherited Methods
From class java.lang.Object
Creates and returns a copy of this Object.
boolean
Compares this instance with the specified object and
indicates if they are equal.
void
Is called before the object's memory is being reclaimed
by the VM.
final Class extends Object>
Returns the unique instance of Class which represents this
object's class.
int
Returns an integer hash code for this
object.
final void
Causes a thread which is waiting on this object's monitor
(by means of calling one of the wait()
methods) to be woken up.
final void
Causes all threads which are waiting on this object's
monitor (by means of calling one of the wait() methods) to be woken up.
Returns a string containing a concise, human-readable
description of this object.
final void
Causes the calling thread to wait until another thread
calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
final void
Causes the calling thread to wait until another thread
calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
final void
Causes the calling thread to wait until another thread
calls the notify() or notifyAll() method of this
object.
Constants
public static final StringCURSOR_DIR_BASE_TYPE
This is the Android platform's base MIME type for a content: URI containing a
Cursor of zero or more items. Applications should use this as the base type
along with their own sub-type of their content: URIs that represent a directory
of items. For example, hypothetical IMAP email client may have a URI
content://com.company.provider.imap/inbox for all of the messages
in its inbox, whose MIME type would be reported as CURSOR_DIR_BASE_TYPE +
"/vnd.company.imap-msg"
Note how the base MIME type varies between this and CURSOR_ITEM_BASE_TYPE
depending on whether there is one single item or multiple items in the data set,
while the sub-type remains the same because in either case the data structure
contained in the cursor is the same.
Constant Value:"vnd.android.cursor.dir"
public static final StringCURSOR_ITEM_BASE_TYPE
This is the Android platform's base MIME type for a content: URI containing a
Cursor of a single item. Applications should use this as the base type along
with their own sub-type of their content: URIs that represent a particular item.
For example, hypothetical IMAP email client may have a URI
content://com.company.provider.imap/inbox/1 for a particular
message in the inbox, whose MIME type would be reported as
CURSOR_ITEM_BASE_TYPE + "/vnd.company.imap-msg"
Constant Value:"vnd.android.cursor.item"
public static final StringSCHEME_ANDROID_RESOURCE
Constant Value:"android.resource"
public static final StringSCHEME_CONTENT
Constant Value:"content"
public static final StringSCHEME_FILE
Constant Value:"file"
public static final StringSYNC_EXTRAS_ACCOUNT
Constant Value:"account"
public static final StringSYNC_EXTRAS_DISCARD_LOCAL_DELETIONS
Constant Value:"discard_deletions"
public static final StringSYNC_EXTRAS_EXPEDITED
Constant Value:"expedited"
public static final StringSYNC_EXTRAS_FORCE
Constant Value:"force"
public static final StringSYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS
Constant Value:"deletions_override"
public static final StringSYNC_EXTRAS_UPLOAD
Constant Value:"upload"
Public Constructors
publicContentResolver (Context
context)
Public Methods
public final intbulkInsert
Inserts multiple rows into a table at the given URL. This function make no
guarantees about the atomicity of the insertions.
Parameters
urlThe URL of the table to insert into.
valuesThe initial values for the newly inserted rows. The key is the column name
for the field. Passing null will create an empty
row.
Returns
the number of newly created rows.
public voidcancelSync (Uri uri)
public final intdelete (Uri url, String where, String[]
selectionArgs)
Deletes row(s) specified by a content URI. If the content provider supports
transactions, the deletion will be atomic.
Parameters
urlThe URL of the row to delete.
whereA filter to apply to rows before deleting, formatted as an SQL WHERE clause
(excluding the WHERE itself).
Returns
The number of rows deleted.
public final StringgetType (Uri url)
Return the MIME type of the given content URL.
Parameters
urlA Uri identifying content (either a list or specific type), using the
content:// scheme.
Returns
A MIME type for the content, or null if the URL is invalid or the type is
unknown
public final Uriinsert
Inserts a row into a table at the given URL. If the content provider supports
transactions the insertion will be atomic.
Parameters
urlThe URL of the table to insert into.
valuesThe initial values for the newly inserted row. The key is the column name
for the field. Passing an empty ContentValues will create an empty
row.
Returns
the URL of the newly created row.
public voidnotifyChange
Notify registered observers that a row was updated. To register, call registerContentObserver().
By default, CursorAdapter objects will get this notification.
Parameters
observerThe observer that originated the change, may be null
public voidnotifyChange (Uri uri, ContentObserver
observer, boolean syncToNetwork)
Notify registered observers that a row was updated. To register, call registerContentObserver().
By default, CursorAdapter objects will get this notification.
Parameters
observerThe observer that originated the change, may be
null
syncToNetworkIf true, attempt to sync the change to the network.
openAssetFileDescriptor (Uri uri, String mode)
Open a raw file descriptor to access data under a "content:" URI. This
interacts with the underlying openAssetFile(Uri,
String) ContentProvider.openAssetFile()} method of the provider associated
with the given URI, to retrieve any file stored there.
Accepts the following URI schemes:
The android.resource (SCHEME_ANDROID_RESOURCE)
Scheme
A Uri object can be used to reference a resource in an APK file. The Uri
should be one of the following formats:android.resource://package_name/id_number
package_name
is your package name as listed in your AndroidManifest.xml. For example
com.example.myapp
id_number is the int form of the
ID.
The easiest way to construct this form is Uri uri = Uri.parse("android.resource://com.example.myapp/" + R.raw.my_resource");
android.resource://package_name/type/name
package_name
is your package name as listed in your AndroidManifest.xml. For example
com.example.myapp
type is the string form of the
resource type. For example, raw or drawable.
name is the string form of the resource name. That is, whatever the
file name was in your res directory, without the type extension. The easiest way
to construct this form is Uri uri = Uri.parse("android.resource://com.example.myapp/raw/my_resource");
Parameters
uriThe desired URI to open.
modeThe file mode to use, as per ContentProvider.openAssetFile.
Returns
Returns a new ParcelFileDescriptor pointing to the file. You own this
descriptor and are responsible for closing it when done.
Throws
Throws FileNotFoundException of no file exists under the URI or the mode is
invalid.
openFileDescriptor (Uri uri, String mode)
Open a raw file descriptor to access data under a "content:" URI. This is
like openAssetFileDescriptor(Uri,
String), but uses the underlying openFile(Uri,
String) ContentProvider.openFile()} method, so will not work with
providers that return sub-sections of files. If at all possible, you should use
openAssetFileDescriptor(Uri,
String). You will receive a FileNotFoundException exception if the provider
returns a sub-section of a file.
Accepts the following URI schemes:
See openAssetFileDescriptor(Uri,
String) for more information on these schemes.
Parameters
uriThe desired URI to open.
modeThe file mode to use, as per ContentProvider.openFile.
Returns
Returns a new ParcelFileDescriptor pointing to the file. You own this
descriptor and are responsible for closing it when done.
Throws
Throws FileNotFoundException of no file exists under the URI or the mode is
invalid.
public final InputStreamopenInputStream (Uri uri)
Open a stream on to the content associated with a content URI. If there is no
data associated with the URI, FileNotFoundException is thrown.
Accepts the following URI schemes:
See openAssetFileDescriptor(Uri,
String) for more information on these schemes.
Parameters
uriThe desired URI.
Returns
InputStream
Throws
if the provided URI could not be opened.
public final OutputStreamopenOutputStream (Uri uri)
Throws
if the provided URI could not be opened.
public final OutputStreamopenOutputStream (Uri uri, String mode)
Open a stream on to the content associated with a content URI. If there is no
data associated with the URI, FileNotFoundException is thrown.
Accepts the following URI schemes:
See openAssetFileDescriptor(Uri,
String) for more information on these schemes.
Parameters
uriThe desired URI.
modeMay be "w", "wa", "rw", or "rwt".
Returns
OutputStream
Throws
if the provided URI could not be opened.
public final Cursorquery (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Query the given URI, returning a Cursor over the
result set.
Parameters
uriThe URI, using the content:// scheme, for the content to retrieve.
projectionA list of which columns to return. Passing null will return all columns,
which is discouraged to prevent reading data from storage that isn't going to be
used.
selectionA filter declaring which rows to return, formatted as an SQL WHERE clause
(excluding the WHERE itself). Passing null will return all rows for the given
URI.
selectionArgsYou may include ?s in selection, which will be replaced by the values from
selectionArgs, in the order that they appear in the selection. The values will
be bound as Strings.
sortOrderHow to order the rows, formatted as an SQL ORDER BY clause (excluding the
ORDER BY itself). Passing null will use the default sort order, which may be
unordered.
Returns
A Cursor object, which is positioned before the first entry, or null