java.lang.Object | |
↳ | android.content.ContentResolver |
![]() |
This class provides applications access to the content model.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | CURSOR_DIR_BASE_TYPE | This is the Android platform's base MIME type for a content: URI containing a Cursor of zero or more items. | |||||||||
String | CURSOR_ITEM_BASE_TYPE | This is the Android platform's base MIME type for a content: URI containing a Cursor of a single item. | |||||||||
String | SCHEME_ANDROID_RESOURCE | ||||||||||
String | SCHEME_CONTENT | ||||||||||
String | SCHEME_FILE | ||||||||||
String | SYNC_EXTRAS_ACCOUNT |
This constant is deprecated.
instead use
requestSync(android.accounts.Account, String, android.os.Bundle)
| |||||||||
String | SYNC_EXTRAS_DISCARD_LOCAL_DELETIONS | ||||||||||
String | SYNC_EXTRAS_DO_NOT_RETRY | If this extra is set to true then the request will not be retried if it fails. | |||||||||
String | SYNC_EXTRAS_EXPEDITED | ||||||||||
String | SYNC_EXTRAS_FORCE |
This constant is deprecated.
instead use
SYNC_EXTRAS_MANUAL
| |||||||||
String | SYNC_EXTRAS_IGNORE_BACKOFF | If this extra is set to true then any backoffs for the initial attempt (e.g. | |||||||||
String | SYNC_EXTRAS_IGNORE_SETTINGS | If this extra is set to true then the sync settings (like getSyncAutomatically()) are ignored by the sync scheduler. | |||||||||
String | SYNC_EXTRAS_INITIALIZE | Set by the SyncManager to request that the SyncAdapter initialize itself for the given account/authority pair. | |||||||||
String | SYNC_EXTRAS_MANUAL | Setting this extra is the equivalent of setting both SYNC_EXTRAS_IGNORE_SETTINGS
and SYNC_EXTRAS_IGNORE_BACKOFF
| |||||||||
String | SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS | ||||||||||
String | SYNC_EXTRAS_UPLOAD | ||||||||||
int | SYNC_OBSERVER_TYPE_ACTIVE | ||||||||||
int | SYNC_OBSERVER_TYPE_PENDING | ||||||||||
int | SYNC_OBSERVER_TYPE_SETTINGS |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a
ContentProviderClient that is associated with the ContentProvider
that services the content at uri, starting the provider if necessary. | |||||||||||
Returns a
ContentProviderClient that is associated with the ContentProvider
with the authority of name, starting the provider if necessary. | |||||||||||
Specifies that a sync should be requested with the specified the account, authority,
and extras at the given frequency.
| |||||||||||
Request notifications when the different aspects of the SyncManager change.
| |||||||||||
Applies each of the
ContentProviderOperation objects and returns an array
of their results. | |||||||||||
Inserts multiple rows into a table at the given URL.
| |||||||||||
Cancel any active or pending syncs that match account and authority.
| |||||||||||
This method is deprecated.
instead use
cancelSync(android.accounts.Account, String)
| |||||||||||
Deletes row(s) specified by a content URI.
| |||||||||||
If a sync is active returns the information about it, otherwise returns false.
| |||||||||||
Check if this account/provider is syncable.
| |||||||||||
Gets the master auto-sync setting that applies to all the providers and accounts.
| |||||||||||
Get the list of information about the periodic syncs for the given account and authority.
| |||||||||||
Get information about the SyncAdapters that are known to the system.
| |||||||||||
Check if the provider should be synced when a network tickle is received
| |||||||||||
Return the MIME type of the given content URL.
| |||||||||||
Inserts a row into a table at the given URL.
| |||||||||||
Returns true if there is currently a sync operation for the given
account or authority in the pending list, or actively being processed.
| |||||||||||
Return true if the pending status is true of any matching authorities.
| |||||||||||
Notify registered observers that a row was updated.
| |||||||||||
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.
| |||||||||||
Synonym for
openOutputStream(uri, "w") . | |||||||||||
Open a stream on to the content associated with a content URI.
| |||||||||||
Query the given URI, returning a | |||||||||||
Register an observer class that gets callbacks when data identified by a
given content URI changes.
| |||||||||||
Remove a periodic sync.
| |||||||||||
Remove a previously registered status change listener.
| |||||||||||
Start an asynchronous sync operation.
| |||||||||||
Set whether this account/provider is syncable.
| |||||||||||
Sets the master auto-sync setting that applies to all the providers and accounts.
| |||||||||||
Set whether or not the provider is synced when it receives a network tickle.
| |||||||||||
This method is deprecated.
instead use
requestSync(android.accounts.Account, String, android.os.Bundle)
| |||||||||||
Unregisters a change observer.
| |||||||||||
Update row(s) in a content URI.
| |||||||||||
Check that only values of the following types are in the Bundle:
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
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.
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"
Compare with CURSOR_DIR_BASE_TYPE
.
This constant is deprecated.
instead use
requestSync(android.accounts.Account, String, android.os.Bundle)
If this extra is set to true then the request will not be retried if it fails.
If this extra is set to true then any backoffs for the initial attempt (e.g. due to retries) are ignored by the sync scheduler. If this request fails and gets rescheduled then the retries will still honor the backoff.
If this extra is set to true then the sync settings (like getSyncAutomatically()) are ignored by the sync scheduler.
Set by the SyncManager to request that the SyncAdapter initialize itself for
the given account/authority pair. One required initialization step is to
ensure that setIsSyncable(android.accounts.Account, String, int)
has been
called with a >= 0 value. When this flag is set the SyncAdapter does not need to
do a full sync, though it is allowed to do so.
Setting this extra is the equivalent of setting both SYNC_EXTRAS_IGNORE_SETTINGS
and SYNC_EXTRAS_IGNORE_BACKOFF
Returns a ContentProviderClient
that is associated with the ContentProvider
that services the content at uri, starting the provider if necessary. Returns
null if there is no provider associated wih the uri. The caller must indicate that they are
done with the provider by calling release()
which will allow
the system to release the provider it it determines that there is no other reason for
keeping it active.
uri | specifies which provider should be acquired |
---|
ContentProviderClient
that is associated with the ContentProvider
that services the content at uri or null if there isn't one.
Returns a ContentProviderClient
that is associated with the ContentProvider
with the authority of name, starting the provider if necessary. Returns
null if there is no provider associated wih the uri. The caller must indicate that they are
done with the provider by calling release()
which will allow
the system to release the provider it it determines that there is no other reason for
keeping it active.
name | specifies which provider should be acquired |
---|
ContentProviderClient
that is associated with the ContentProvider
with the authority of name or null if there isn't one.
Specifies that a sync should be requested with the specified the account, authority, and extras at the given frequency. If there is already another periodic sync scheduled with the account, authority and extras then a new periodic sync won't be added, instead the frequency of the previous one will be updated.
These periodic syncs honor the "syncAutomatically" and "masterSyncAutomatically" settings. Although these sync are scheduled at the specified frequency, it may take longer for it to actually be started if other syncs are ahead of it in the sync operation queue. This means that the actual start time may drift.
Periodic syncs are not allowed to have any of SYNC_EXTRAS_DO_NOT_RETRY
,
SYNC_EXTRAS_IGNORE_BACKOFF
, SYNC_EXTRAS_IGNORE_SETTINGS
,
SYNC_EXTRAS_INITIALIZE
, SYNC_EXTRAS_FORCE
,
SYNC_EXTRAS_EXPEDITED
, SYNC_EXTRAS_MANUAL
set to true.
If any are supplied then an IllegalArgumentException
will be thrown.
account | the account to specify in the sync |
---|---|
authority | the provider to specify in the sync request |
extras | extra parameters to go along with the sync request |
pollFrequency | how frequently the sync should be performed, in seconds. |
IllegalArgumentException | if an illegal extra was set or if any of the parameters are null. |
---|
Request notifications when the different aspects of the SyncManager change. The different items that can be requested are:
The caller can set one or more of the status types in the mask for any given listener registration.mask | the status change types that will cause the callback to be invoked |
---|---|
callback | observer to be invoked when the status changes |
Applies each of the ContentProviderOperation
objects and returns an array
of their results. Passes through OperationApplicationException, which may be thrown
by the call to apply(ContentProvider, ContentProviderResult[], int)
.
If all the applications succeed then a ContentProviderResult
array with the
same number of elements as the operations will be returned. It is implementation-specific
how many, if any, operations will have been successfully applied if a call to
apply results in a OperationApplicationException
.
authority | the authority of the ContentProvider to which this batch should be applied |
---|---|
operations | the operations to apply |
OperationApplicationException | thrown if an application fails.
See apply(ContentProvider, ContentProviderResult[], int) for more information. |
---|---|
RemoteException | thrown if a RemoteException is encountered while attempting to communicate with a remote provider. |
Inserts multiple rows into a table at the given URL. This function make no guarantees about the atomicity of the insertions.
url | The URL of the table to insert into. |
---|---|
values | The initial values for the newly inserted rows. The key is the column name for the field. Passing null will create an empty row. |
Cancel any active or pending syncs that match account and authority. The account and authority can each independently be set to null, which means that syncs with any account or authority, respectively, will match.
account | filters the syncs that match by this account |
---|---|
authority | filters the syncs that match by this authority |
This method is deprecated.
instead use cancelSync(android.accounts.Account, String)
Cancel any active or pending syncs that match the Uri. If the uri is null then all syncs will be canceled.
uri | the uri of the provider to sync or null to sync all providers. |
---|
Deletes row(s) specified by a content URI. If the content provider supports transactions, the deletion will be atomic.
url | The URL of the row to delete. |
---|---|
where | A filter to apply to rows before deleting, formatted as an SQL WHERE clause (excluding the WHERE itself). |
If a sync is active returns the information about it, otherwise returns false.
Check if this account/provider is syncable.
Gets the master auto-sync setting that applies to all the providers and accounts. If this is false then the per-provider auto-sync setting is ignored.
Get the list of information about the periodic syncs for the given account and authority.
account | the account whose periodic syncs we are querying |
---|---|
authority | the provider whose periodic syncs we are querying |
Get information about the SyncAdapters that are known to the system.
Check if the provider should be synced when a network tickle is received
account | the account whose setting we are querying |
---|---|
authority | the provider whose setting we are querying |
Return the MIME type of the given content URL.
url | A Uri identifying content (either a list or specific type), using the content:// scheme. |
---|
Inserts a row into a table at the given URL. If the content provider supports transactions the insertion will be atomic.
url | The URL of the table to insert into. |
---|---|
values | The 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 true if there is currently a sync operation for the given account or authority in the pending list, or actively being processed.
account | the account whose setting we are querying |
---|---|
authority | the provider whose behavior is being queried |
Return true if the pending status is true of any matching authorities.
account | the account whose setting we are querying |
---|---|
authority | the provider whose behavior is being queried |
Notify registered observers that a row was updated.
To register, call registerContentObserver()
.
By default, CursorAdapter objects will get this notification.
observer | The observer that originated the change, may be null |
---|---|
syncToNetwork
| If true, attempt to sync the change to the network.
|
public
void
notifyChange
(Uri uri, ContentObserver observer)
Since: API Level 1
Notify registered observers that a row was updated.
To register, call
registerContentObserver()
.
By default, CursorAdapter objects will get this notification.
Parameters
observer
| The observer that originated the change, may be |
---|
public
final
AssetFileDescriptor
openAssetFileDescriptor
(Uri uri, String mode)
Since: API Level 3
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:
content (SCHEME_CONTENT
)
android.resource (SCHEME_ANDROID_RESOURCE
)
file (SCHEME_FILE
)
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
|
|
---|---|
|
|
Returns
Returns a new ParcelFileDescriptor pointing to the file. You
own this descriptor and are responsible for closing it when done.
Throws
|
|
---|
public
final
ParcelFileDescriptor
openFileDescriptor
(Uri uri, String mode)
Since: API Level 1
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:
content (SCHEME_CONTENT
)
file (SCHEME_FILE
)
See
openAssetFileDescriptor(Uri, String)
for more information
on these schemes.
Returns
Returns a new ParcelFileDescriptor pointing to the file. You
own this descriptor and are responsible for closing it when done.
Throws
|
|
---|
public
final
InputStream
openInputStream
(Uri uri)
Since: API Level 1
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:
content (SCHEME_CONTENT
)
android.resource (SCHEME_ANDROID_RESOURCE
)
file (SCHEME_FILE
)
See
openAssetFileDescriptor(Uri, String)
for more information
on these schemes.
Parameters
|
|
---|
Returns
InputStream
public
final
OutputStream
openOutputStream
(Uri uri, String mode)
Since: API Level 3
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:
content (SCHEME_CONTENT
)
file (SCHEME_FILE
)
See
openAssetFileDescriptor(Uri, String)
for more information
on these schemes.
Parameters
|
|
---|---|
|
|
Returns
OutputStream
public
final
Cursor
query
(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Since: API Level 1
Query the given URI, returning a
Cursor
over the result set.
For best performance, the caller should follow these guidelines:
Provide an explicit projection, to prevent
reading data from storage that aren't going to be used.
Use question mark parameter markers such as 'phone=?' instead of
explicit values in the selection
parameter, so that queries
that differ only by those values will be recognized as the same
for caching purposes.
Parameters
|
|
---|---|
|
|
|
|
|
|
|
|
Returns
A Cursor object, which is positioned before the first entry, or null
public
final
void
registerContentObserver
(Uri uri, boolean notifyForDescendents, ContentObserver observer)
Since: API Level 1
Register an observer class that gets callbacks when data identified by a
given content URI changes.
Parameters
|
|
---|---|
|
|
|
|
public
static
void
removePeriodicSync
(Account account, String authority, Bundle extras)
Since: API Level 8
Remove a periodic sync. Has no affect if account, authority and extras don't match
an existing periodic sync.
Parameters
|
|
---|---|
|
|
|
|
public
static
void
removeStatusChangeListener
(Object handle)
Since: API Level 5
Remove a previously registered status change listener.
public
static
void
requestSync
(Account account, String authority, Bundle extras)
Since: API Level 5
Start an asynchronous sync operation. If you want to monitor the progress
of the sync you may register a SyncObserver. Only values of the following
types may be used in the extras bundle:
Integer
Long
Boolean
Float
Double
String
Parameters
|
|
---|---|
|
|
|
|
public
static
void
setIsSyncable
(Account account, String authority, int syncable)
Since: API Level 5
Set whether this account/provider is syncable.
Parameters
|
|
---|
public
static
void
setMasterSyncAutomatically
(boolean sync)
Since: API Level 5
Sets the master auto-sync setting that applies to all the providers and accounts.
If this is false then the per-provider auto-sync setting is ignored.
Parameters
|
|
---|
public
static
void
setSyncAutomatically
(Account account, String authority, boolean sync)
Since: API Level 5
Set whether or not the provider is synced when it receives a network tickle.
Parameters
|
|
---|---|
|
|
|
|
public
void
startSync
(Uri uri, Bundle extras)
Since: API Level 1
This method is deprecated.
instead use
requestSync(android.accounts.Account, String, android.os.Bundle)
Start an asynchronous sync operation. If you want to monitor the progress
of the sync you may register a SyncObserver. Only values of the following
types may be used in the extras bundle:
Integer
Long
Boolean
Float
Double
String
Parameters
|
|
---|---|
|
|
public
final
void
unregisterContentObserver
(ContentObserver observer)
Since: API Level 1
Unregisters a change observer.
Parameters
|
|
---|
public
final
int
update
(Uri uri, ContentValues values, String where, String[] selectionArgs)
Since: API Level 1
Update row(s) in a content URI.
If the content provider supports transactions the update will be atomic.
Parameters
|
|
---|---|
|
|
|
|
Returns
The number of rows updated.
public
static
void
validateSyncExtrasBundle
(Bundle extras)
Since: API Level 1
Check that only values of the following types are in the Bundle:
Integer
Long
Boolean
Float
Double
String
Account
null
Parameters
|
|
---|