Android Guides | Samples

Android.Content.ContentResolver Class

This class provides applications access to the content model.

See Also: ContentResolver

Syntax

[Android.Runtime.Register("android/content/ContentResolver", DoNotGenerateAcw=true)]
public abstract class ContentResolver : Object

Remarks

This class provides applications access to the content model.

Developer Guides

For more information about using a ContentResolver with content providers, read the Content Providers developer guide.

Summary

Constants
StringContentResolver.AnyCursorItemType This is the Android platform's generic MIME type to match any MIME type of the form "ContentResolver.CursorItemBaseType/SUB_TYPE".
StringContentResolver.CursorDirBaseType This is the Android platform's base MIME type for a content: URI containing a Cursor of zero or more items.
StringContentResolver.CursorItemBaseType This is the Android platform's base MIME type for a content: URI containing a Cursor of a single item.
StringContentResolver.ExtraSize An extra Point describing the optimal size for a requested image resource, in pixels.
StringContentResolver.SchemeAndroidResource
StringContentResolver.SchemeContent
StringContentResolver.SchemeFile
StringContentResolver.SyncExtrasAccount This constant was deprecated in API level 5. instead use ContentResolver.RequestSync(Account,String,String)
StringContentResolver.SyncExtrasDiscardLocalDeletions Indicates that the sync adapter should not proceed with the delete operations, if it determines that there are too many.
StringContentResolver.SyncExtrasDoNotRetry If this extra is set to true then the request will not be retried if it fails.
StringContentResolver.SyncExtrasExpedited If this extra is set to true, the sync request will be scheduled at the front of the sync request queue and without any delay
StringContentResolver.SyncExtrasForce This constant was deprecated in API level 5. instead use ContentResolver.SyncExtrasManual
StringContentResolver.SyncExtrasIgnoreBackoff If this extra is set to true then any backoffs for the initial attempt (e.g.
StringContentResolver.SyncExtrasIgnoreSettings If this extra is set to true then the sync settings (like getSyncAutomatically()) are ignored by the sync scheduler.
StringContentResolver.SyncExtrasInitialize Set by the SyncManager to request that the SyncAdapter initialize itself for the given account/authority pair.
StringContentResolver.SyncExtrasManual Setting this extra is the equivalent of setting both ContentResolver.SyncExtrasIgnoreSettings and ContentResolver.SyncExtrasIgnoreBackoff
StringContentResolver.SyncExtrasOverrideTooManyDeletions Indicates that the sync adapter should proceed with the delete operations, even if it determines that there are too many.
StringContentResolver.SyncExtrasUpload Indicates that this sync is intended to only upload local changes to the server.
intContentResolver.SyncObserverTypeActive
intContentResolver.SyncObserverTypePending
intContentResolver.SyncObserverTypeSettings
Public Constructors
ContentResolver.ContentResolver(Context)(Context context)
Public Methods
final ContentProviderClientContentResolver.AcquireContentProviderClient(Uri)(Uri uri) Returns a ContentProviderClient that is associated with the ContentProvider that services the content at uri, starting the provider if necessary.
final ContentProviderClientContentResolver.AcquireContentProviderClient(String)(String name) Returns a ContentProviderClient that is associated with the ContentProvider with the authority of name, starting the provider if necessary.
final ContentProviderClientContentResolver.AcquireUnstableContentProviderClient(Uri)(Uri uri) Like ContentResolver.AcquireContentProviderClient(Uri), but for use when you do not trust the stability of the target content provider.
final ContentProviderClientContentResolver.AcquireUnstableContentProviderClient(String)(String name) Like ContentResolver.AcquireContentProviderClient(String), but for use when you do not trust the stability of the target content provider.
static voidContentResolver.AddPeriodicSync(Account,String,String,String)(Account account, String authority, Bundle extras, long pollFrequency) Specifies that a sync should be requested with the specified the account, authority, and extras at the given frequency.
static ObjectContentResolver.AddStatusChangeListener(SyncObserverType,ISyncStatusObserver)(int mask, ISyncStatusObserver callback) Request notifications when the different aspects of the SyncManager change.
ContentProviderResultContentResolver.applyBatch(java.lang.String, java.util.ArrayList<android.content.ContentProviderOperation>)(String authority, JavaList<ContentProviderOperation> operations) Applies each of the ContentProviderOperation objects and returns an array of their results.
final intContentResolver.BulkInsert(Uri,ContentValues[])(Uri url, ContentValues values) Inserts multiple rows into a table at the given URL.
final BundleContentResolver.Call(Uri,String,String,String)(Uri uri, String method, String arg, Bundle extras) Call a provider-defined method.
static voidContentResolver.CancelSync(SyncRequest)(SyncRequest request) Remove the specified sync.
static voidContentResolver.CancelSync(Account,String)(Account account, String authority) Cancel any active or pending syncs that match account and authority.
voidContentResolver.CancelSync(Uri)(Uri uri) This method was deprecated in API level 5. instead use ContentResolver.CancelSync(Account,String)
final UriContentResolver.Canonicalize(Uri)(Uri url) Transform the given url to a canonical representation of its referenced resource, which can be used across devices, persisted, backed up and restored, etc.
final intContentResolver.Delete(Uri,String,String)(Uri url, String where, String selectionArgs) Deletes row(s) specified by a content URI.
static SyncInfoContentResolver.CurrentSync() This method was deprecated in API level 11. Since multiple concurrent syncs are now supported you should use ContentResolver.CurrentSyncs to get the accurate list of current syncs. This method returns the first item from the list of current syncs or null if there are none.
static IList<SyncInfo>ContentResolver.CurrentSyncs() Returns a list with information about all the active syncs.
static intContentResolver.GetIsSyncable(Account,String)(Account account, String authority) Check if this account/provider is syncable.
static booleanContentResolver.MasterSyncAutomatically() Gets the master auto-sync setting that applies to all the providers and accounts.
IList<UriPermission>ContentResolver.OutgoingPersistedUriPermissions() Return list of all persisted URI permission grants that are hosted by the calling app.
static IList<PeriodicSync>ContentResolver.GetPeriodicSyncs(Account,String)(Account account, String authority) Get the list of information about the periodic syncs for the given account and authority.
IList<UriPermission>ContentResolver.PersistedUriPermissions() Return list of all URI permission grants that have been persisted by the calling app.
StringContentResolver.GetStreamTypes(Uri,String)(Uri url, String mimeTypeFilter) Query for the possible MIME types for the representations the given content URL can be returned when opened as as stream with ContentResolver.OpenTypedAssetFileDescriptor(Uri,String,String).
static SyncAdapterTypeContentResolver.GetSyncAdapterTypes() Get information about the SyncAdapters that are known to the system.
static booleanContentResolver.GetSyncAutomatically(Account,String)(Account account, String authority) Check if the provider should be synced when a network tickle is received This method requires the caller to hold the permission NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#READ_SYNC_SETTINGS.
final StringContentResolver.GetType(Uri)(Uri url) Return the MIME type of the given content URL.
final UriContentResolver.Insert(Uri,ContentValues)(Uri url, ContentValues values) Inserts a row into a table at the given URL.
static booleanContentResolver.IsSyncActive(Account,String)(Account account, String authority) Returns true if there is currently a sync operation for the given account or authority actively being processed.
static booleanContentResolver.IsSyncPending(Account,String)(Account account, String authority) Return true if the pending status is true of any matching authorities.
voidContentResolver.NotifyChange(Uri,ContentObserver,ContentObserver)(Uri uri, ContentObserver observer, boolean syncToNetwork) Notify registered observers that a row was updated.
voidContentResolver.NotifyChange(Uri,ContentObserver)(Uri uri, ContentObserver observer) Notify registered observers that a row was updated and attempt to sync changes to the network.
final AssetFileDescriptorContentResolver.OpenAssetFileDescriptor(Uri,String)(Uri uri, String mode) Open a raw file descriptor to access data under a URI.
final AssetFileDescriptorContentResolver.OpenAssetFileDescriptor(Uri,String,String)(Uri uri, String mode, CancellationSignal cancellationSignal) Open a raw file descriptor to access data under a URI.
final ParcelFileDescriptorContentResolver.OpenFileDescriptor(Uri,String,String)(Uri uri, String mode, CancellationSignal cancellationSignal) Open a raw file descriptor to access data under a URI.
final ParcelFileDescriptorContentResolver.OpenFileDescriptor(Uri,String)(Uri uri, String mode) Open a raw file descriptor to access data under a URI.
final InputStreamContentResolver.OpenInputStream(Uri)(Uri uri) Open a stream on to the content associated with a content URI.
final OutputStreamContentResolver.OpenOutputStream(Uri)(Uri uri) Synonym for ContentResolver.OpenOutputStream(Uri,String).
final OutputStreamContentResolver.OpenOutputStream(Uri,String)(Uri uri, String mode) Open a stream on to the content associated with a content URI.
final AssetFileDescriptorContentResolver.OpenTypedAssetFileDescriptor(Uri,String,String,String)(Uri uri, String mimeType, Bundle opts, CancellationSignal cancellationSignal) Open a raw file descriptor to access (potentially type transformed) data from a "content:" URI.
final AssetFileDescriptorContentResolver.OpenTypedAssetFileDescriptor(Uri,String,String)(Uri uri, String mimeType, Bundle opts) Open a raw file descriptor to access (potentially type transformed) data from a "content:" URI.
final ICursorContentResolver.Query(Uri,String[],String[],String[],String[])(Uri uri, String projection, String selection, String selectionArgs, String sortOrder) Query the given URI, returning a ICursor over the result set.
final ICursorContentResolver.Query(Uri,String[],String[],String[],String[],String[])(Uri uri, String projection, String selection, String selectionArgs, String sortOrder, CancellationSignal cancellationSignal) Query the given URI, returning a ICursor over the result set with optional support for cancellation.
final voidContentResolver.RegisterContentObserver(Uri,Boolean,Boolean)(Uri uri, boolean notifyForDescendents, ContentObserver observer) Register an observer class that gets callbacks when data identified by a given content URI changes.
voidContentResolver.ReleasePersistableUriPermission(Uri,ActivityFlags)(Uri uri, int modeFlags) Relinquish a persisted URI permission grant.
static voidContentResolver.RemovePeriodicSync(Account,String,String)(Account account, String authority, Bundle extras) Remove a periodic sync.
static voidContentResolver.RemoveStatusChangeListener(Object)(Object handle) Remove a previously registered status change listener.
static voidContentResolver.RequestSync(Account,String,String)(Account account, String authority, Bundle extras) Start an asynchronous sync operation.
static voidContentResolver.RequestSync(SyncRequest)(SyncRequest request) Register a sync with the SyncManager.
static voidContentResolver.SetIsSyncable(Account,String,String)(Account account, String authority, int syncable) Set whether this account/provider is syncable.
static voidContentResolver.MasterSyncAutomatically(boolean sync) Sets the master auto-sync setting that applies to all the providers and accounts.
static voidContentResolver.SetSyncAutomatically(Account,String,String)(Account account, String authority, boolean sync) Set whether or not the provider is synced when it receives a network tickle.
voidContentResolver.StartSync(Uri,Bundle)(Uri uri, Bundle extras) This method was deprecated in API level 5. instead use ContentResolver.RequestSync(Account,String,String)
voidContentResolver.TakePersistableUriPermission(Uri,ActivityFlags)(Uri uri, int modeFlags) Take a persistable URI permission grant that has been offered.
final UriContentResolver.Uncanonicalize(Uri)(Uri url) Given a canonical Uri previously generated by ContentResolver.Canonicalize(Uri), convert it to its local non-canonical form.
final voidContentResolver.UnregisterContentObserver(ContentObserver)(ContentObserver observer) Unregisters a change observer.
final intContentResolver.Update(Uri,ContentValues,ContentValues,ContentValues)(Uri uri, ContentValues values, String where, String selectionArgs) Update row(s) in a content URI.
static voidContentResolver.ValidateSyncExtrasBundle(Bundle)(Bundle extras) Check that only values of the following types are in the Bundle:
  • Integer
  • Long
  • Boolean
  • Float
  • Double
  • String
  • Account
  • null

Inherited Methods
From class Object
ObjectObject.Clone() Creates and returns a copy of this Object.
booleanObject.Equals(Object)(Object o) Compares this instance with the specified object and indicates if they are equal.
voidObject.JavaFinalize() Invoked when the garbage collector has detected that this instance is no longer reachable.
final Class<?>Object.Class() Returns the unique instance of Class that represents this object's class.
intObject.GetHashCode() Returns an integer hash code for this object.
final voidObject.Notify() 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 voidObject.NotifyAll() Causes all threads which are waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.
StringObject.ToString() Returns a string containing a concise, human-readable description of this object.
final voidObject.Wait() Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
final voidObject.Wait(Int64,Int32)(long millis, int nanos) 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 voidObject.Wait(Int64)(long millis) Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

Constants

public static final String ANY_CURSOR_ITEM_TYPE

Added in API level 21

This is the Android platform's generic MIME type to match any MIME type of the form "ContentResolver.CursorItemBaseType/SUB_TYPE". SUB_TYPE is the sub-type of the application-dependent content, e.g., "audio", "video", "playlist".

Constant Value: "vnd.android.cursor.item/*"

public static final String CURSOR_DIR_BASE_TYPE

Added in API level 1

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 ContentResolver.CursorItemBaseType 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 String CURSOR_ITEM_BASE_TYPE

Added in API level 1

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 ContentResolver.CursorDirBaseType.

Constant Value: "vnd.android.cursor.item"

public static final String EXTRA_SIZE

Added in API level 21

An extra Point describing the optimal size for a requested image resource, in pixels. If a provider has multiple sizes of the image, it should return the image closest to this size.

See Also
Constant Value: "android.content.extra.SIZE"

public static final String SCHEME_ANDROID_RESOURCE

Added in API level 1

Constant Value: "android.resource"

public static final String SCHEME_CONTENT

Added in API level 1

Constant Value: "content"

public static final String SCHEME_FILE

Added in API level 1

Constant Value: "file"

public static final String SYNC_EXTRAS_ACCOUNT

Added in API level 1

This constant was deprecated in API level 5.
instead use ContentResolver.RequestSync(Account,String,String)

Constant Value: "account"

public static final String SYNC_EXTRAS_DISCARD_LOCAL_DELETIONS

Added in API level 1

Indicates that the sync adapter should not proceed with the delete operations, if it determines that there are too many. See SyncResult.TooManyDeletions

Constant Value: "discard_deletions"

public static final String SYNC_EXTRAS_DO_NOT_RETRY

Added in API level 8

If this extra is set to true then the request will not be retried if it fails. Constant Value: "do_not_retry"

public static final String SYNC_EXTRAS_EXPEDITED

Added in API level 1

If this extra is set to true, the sync request will be scheduled at the front of the sync request queue and without any delay Constant Value: "expedited"

public static final String SYNC_EXTRAS_FORCE

Added in API level 1

This constant was deprecated in API level 5.
instead use ContentResolver.SyncExtrasManual

Constant Value: "force"

public static final String SYNC_EXTRAS_IGNORE_BACKOFF

Added in API level 8

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. Constant Value: "ignore_backoff"

public static final String SYNC_EXTRAS_IGNORE_SETTINGS

Added in API level 8

If this extra is set to true then the sync settings (like getSyncAutomatically()) are ignored by the sync scheduler. Constant Value: "ignore_settings"

public static final String SYNC_EXTRAS_INITIALIZE

Added in API level 5

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 ContentResolver.SetIsSyncable(Account,String,String) 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.

Constant Value: "initialize"

public static final String SYNC_EXTRAS_MANUAL

Added in API level 5

Setting this extra is the equivalent of setting both ContentResolver.SyncExtrasIgnoreSettings and ContentResolver.SyncExtrasIgnoreBackoff

Constant Value: "force"

public static final String SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS

Added in API level 1

Indicates that the sync adapter should proceed with the delete operations, even if it determines that there are too many. See SyncResult.TooManyDeletions

Constant Value: "deletions_override"

public static final String SYNC_EXTRAS_UPLOAD

Added in API level 1

Indicates that this sync is intended to only upload local changes to the server. For example, this will be set to true if the sync is initiated by a call to ContentResolver.NotifyChange(Uri,ContentObserver,ContentObserver)

Constant Value: "upload"

public static final int SYNC_OBSERVER_TYPE_ACTIVE

Added in API level 8

Constant Value: 4 (0x00000004)

public static final int SYNC_OBSERVER_TYPE_PENDING

Added in API level 8

Constant Value: 2 (0x00000002)

public static final int SYNC_OBSERVER_TYPE_SETTINGS

Added in API level 8

Constant Value: 1 (0x00000001)

Public Constructors

public ContentResolver(Context context)

Added in API level 1

Public Methods

public final ContentProviderClientacquireContentProviderClient(Uri uri)

Added in API level 5

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 ContentProviderClient.Release which will allow the system to release the provider it it determines that there is no other reason for keeping it active.

Parameters
uri specifies which provider should be acquired
Returns

public final ContentProviderClientacquireContentProviderClient(String name)

Added in API level 5

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 ContentProviderClient.Release which will allow the system to release the provider it it determines that there is no other reason for keeping it active.

Parameters
name specifies which provider should be acquired
Returns

public final ContentProviderClientacquireUnstableContentProviderClient(Uri uri)

Added in API level 16

Like ContentResolver.AcquireContentProviderClient(Uri), but for use when you do not trust the stability of the target content provider. This turns off the mechanism in the platform clean up processes that are dependent on a content provider if that content provider's process goes away. Normally you can safely assume that once you have acquired a provider, you can freely use it as needed and it won't disappear, even if your process is in the background. If using this method, you need to take care to deal with any failures when communicating with the provider, and be sure to close it so that it can be re-opened later. In particular, catching a DeadObjectException from the calls there will let you know that the content provider has gone away; at that point the current ContentProviderClient object is invalid, and you should release it. You can acquire a new one if you would like to try to restart the provider and perform new operations on it.

public final ContentProviderClientacquireUnstableContentProviderClient(String name)

Added in API level 16

Like ContentResolver.AcquireContentProviderClient(String), but for use when you do not trust the stability of the target content provider. This turns off the mechanism in the platform clean up processes that are dependent on a content provider if that content provider's process goes away. Normally you can safely assume that once you have acquired a provider, you can freely use it as needed and it won't disappear, even if your process is in the background. If using this method, you need to take care to deal with any failures when communicating with the provider, and be sure to close it so that it can be re-opened later. In particular, catching a DeadObjectException from the calls there will let you know that the content provider has gone away; at that point the current ContentProviderClient object is invalid, and you should release it. You can acquire a new one if you would like to try to restart the provider and perform new operations on it.

public static void addPeriodicSync(Account account, String authority, Bundle extras, long pollFrequency)

Added in API level 8

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 ContentResolver.SyncExtrasDoNotRetry, ContentResolver.SyncExtrasIgnoreBackoff, ContentResolver.SyncExtrasIgnoreSettings, ContentResolver.SyncExtrasInitialize, ContentResolver.SyncExtrasForce, ContentResolver.SyncExtrasExpedited, ContentResolver.SyncExtrasManual set to true. If any are supplied then an IllegalArgumentException will be thrown.

This method requires the caller to hold the permission Permission.WriteSyncSettings.

The bundle for a periodic sync can be queried by applications with the correct permissions using ContentResolver.GetPeriodicSyncs(Account,String), so no sensitive data should be transferred here.

Parameters
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.
Throws
IllegalArgumentExceptionif an illegal extra was set or if any of the parameters are null.

public static ObjectaddStatusChangeListener(int mask, ISyncStatusObserver callback)

Added in API level 5

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.

Parameters
mask the status change types that will cause the callback to be invoked
callback observer to be invoked when the status changes
Returns
  • a handle that can be used to remove the listener at a later time

public ContentProviderResultapplyBatch(String authority, JavaList<ContentProviderOperation> operations)

Added in API level 5

Applies each of the ContentProviderOperation objects and returns an array of their results. Passes through OperationApplicationException, which may be thrown by the call to ContentProviderOperation.Apply(ContentProvider,ContentProviderResult[],ContentProviderResult[]). 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.

Parameters
authority the authority of the ContentProvider to which this batch should be applied
operations the operations to apply
Returns
  • the results of the applications
Throws
OperationApplicationExceptionthrown if an application fails. See ContentProviderOperation.Apply(ContentProvider,ContentProviderResult[],ContentProviderResult[]) for more information.
RemoteExceptionthrown if a RemoteException is encountered while attempting to communicate with a remote provider.

public final int bulkInsert(Uri url, ContentValues values)

Added in API level 1

Inserts multiple rows into a table at the given URL. This function make no guarantees about the atomicity of the insertions.

Parameters
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.
Returns
  • the number of newly created rows.

public final Bundlecall(Uri uri, String method, String arg, Bundle extras)

Added in API level 11

Call a provider-defined method. This can be used to implement read or write interfaces which are cheaper than using a Cursor and/or do not fit into the traditional table model.

Parameters
method provider-defined method name to call. Opaque to framework, but must be non-null.
arg provider-defined String argument. May be null.
extras provider-defined Bundle argument. May be null.
Returns
  • a result Bundle, possibly null. Will be null if the ContentProvider does not implement call.
Throws
NullPointerExceptionif uri or method is null
IllegalArgumentExceptionif uri is not known

public static void cancelSync(SyncRequest request)

Added in API level 21

Remove the specified sync. This will cancel any pending or active syncs. If the request is for a periodic sync, this call will remove any future occurrences. It is possible to cancel a sync using a SyncRequest object that is not the same object with which you requested the sync. Do so by building a SyncRequest with the same adapter, frequency, and extras bundle.

If a periodic sync is specified, the caller must hold the permission Permission.WriteSyncSettings.

Parameters
request SyncRequest object containing information about sync to cancel.

public static void cancelSync(Account account, String authority)

Added in API level 5

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.

Parameters
account filters the syncs that match by this account
authority filters the syncs that match by this authority

public void cancelSync(Uri uri)

Added in API level 1

This method was deprecated in API level 5.
instead use ContentResolver.CancelSync(Account,String)

Cancel any active or pending syncs that match the Uri. If the uri is null then all syncs will be canceled.

Parameters
uri the uri of the provider to sync or null to sync all providers.

public final Uricanonicalize(Uri url)

Added in API level 19

Transform the given url to a canonical representation of its referenced resource, which can be used across devices, persisted, backed up and restored, etc. The returned Uri is still a fully capable Uri for use with its content provider, allowing you to do all of the same content provider operations as with the original Uri -- ContentResolver.Query(Uri,String[],String[],String[],String[]), ContentResolver.OpenInputStream(Uri), etc. The only difference in behavior between the original and new Uris is that the content provider may need to do some additional work at each call using it to resolve it to the correct resource, especially if the canonical Uri has been moved to a different environment.

If you are moving a canonical Uri between environments, you should perform another call to ContentResolver.Canonicalize(Uri) with that original Uri to re-canonicalize it for the current environment. Alternatively, you may want to use ContentResolver.Uncanonicalize(Uri) to transform it to a non-canonical Uri that works only in the current environment but potentially more efficiently than the canonical representation.

Parameters
url The Uri that is to be transformed to a canonical representation. Like all resolver calls, the input can be either a non-canonical or canonical Uri.
Returns
  • Returns the official canonical representation of url, or null if the content provider does not support a canonical representation of the given Uri. Many providers may not support canonicalization of some or all of their Uris.
See Also

public final int delete(Uri url, String where, String selectionArgs)

Added in API level 1

Deletes row(s) specified by a content URI. If the content provider supports transactions, the deletion will be atomic.

Parameters
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).
Returns
  • The number of rows deleted.

public static SyncInfogetCurrentSync()

Added in API level 8

This method was deprecated in API level 11.
Since multiple concurrent syncs are now supported you should use ContentResolver.CurrentSyncs to get the accurate list of current syncs. This method returns the first item from the list of current syncs or null if there are none.

If a sync is active returns the information about it, otherwise returns null.

This method requires the caller to hold the permission NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#READ_SYNC_STATS.

Returns
  • the SyncInfo for the currently active sync or null if one is not active.

public static IList<SyncInfo> getCurrentSyncs()

Added in API level 11

Returns a list with information about all the active syncs. This list will be empty if there are no active syncs.

This method requires the caller to hold the permission NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#READ_SYNC_STATS.

Returns
  • a List of SyncInfo objects for the currently active syncs.

public static int getIsSyncable(Account account, String authority)

Added in API level 5

Check if this account/provider is syncable.

This method requires the caller to hold the permission NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#READ_SYNC_SETTINGS.

Returns
  • >0 if it is syncable, 0 if not, and <0 if the state isn't known yet.

public static boolean getMasterSyncAutomatically()

Added in API level 5

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.

This method requires the caller to hold the permission NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#READ_SYNC_SETTINGS.

Returns
  • the master auto-sync setting that applies to all the providers and accounts

public IList<UriPermission> getOutgoingPersistedUriPermissions()

Added in API level 19

Return list of all persisted URI permission grants that are hosted by the calling app. That is, the returned permissions have been granted from the calling app. Only grants taken with ContentResolver.TakePersistableUriPermission(Uri,ActivityFlags) are returned.

public static IList<PeriodicSync> getPeriodicSyncs(Account account, String authority)

Added in API level 8

Get the list of information about the periodic syncs for the given account and authority.

This method requires the caller to hold the permission NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#READ_SYNC_SETTINGS.

Parameters
account the account whose periodic syncs we are querying
authority the provider whose periodic syncs we are querying
Returns
  • a list of PeriodicSync objects. This list may be empty but will never be null.

public IList<UriPermission> getPersistedUriPermissions()

Added in API level 19

Return list of all URI permission grants that have been persisted by the calling app. That is, the returned permissions have been granted to the calling app. Only persistable grants taken with ContentResolver.TakePersistableUriPermission(Uri,ActivityFlags) are returned.

See Also

public StringgetStreamTypes(Uri url, String mimeTypeFilter)

Added in API level 11

Query for the possible MIME types for the representations the given content URL can be returned when opened as as stream with ContentResolver.OpenTypedAssetFileDescriptor(Uri,String,String). Note that the types here are not necessarily a superset of the type returned by ContentResolver.GetType(Uri) -- many content providers cannot return a raw stream for the structured data that they contain.

Parameters
url A Uri identifying content (either a list or specific type), using the content:// scheme.
mimeTypeFilter The desired MIME type. This may be a pattern, such as *&#47;*, to query for all available MIME types that match the pattern.
Returns
  • Returns an array of MIME type strings for all available data streams that match the given mimeTypeFilter. If there are none, null is returned.

public static SyncAdapterTypegetSyncAdapterTypes()

Added in API level 5

Get information about the SyncAdapters that are known to the system.

Returns
  • an array of SyncAdapters that have registered with the system

public static boolean getSyncAutomatically(Account account, String authority)

Added in API level 5

Check if the provider should be synced when a network tickle is received

This method requires the caller to hold the permission NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#READ_SYNC_SETTINGS.

Parameters
account the account whose setting we are querying
authority the provider whose setting we are querying
Returns
  • true if the provider should be synced when a network tickle is received

public final StringgetType(Uri url)

Added in API level 1

Return the MIME type of the given content URL.

Parameters
url A 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(Uri url, ContentValues values)

Added in API level 1

Inserts a row into a table at the given URL. If the content provider supports transactions the insertion will be atomic.

Parameters
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
  • the URL of the newly created row.

public static boolean isSyncActive(Account account, String authority)

Added in API level 5

Returns true if there is currently a sync operation for the given account or authority actively being processed.

This method requires the caller to hold the permission NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#READ_SYNC_STATS.

Parameters
account the account whose setting we are querying
authority the provider whose behavior is being queried
Returns
  • true if a sync is active for the given account or authority.

public static boolean isSyncPending(Account account, String authority)

Added in API level 5

Return true if the pending status is true of any matching authorities.

This method requires the caller to hold the permission NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#READ_SYNC_STATS.

Parameters
account the account whose setting we are querying
authority the provider whose behavior is being queried
Returns
  • true if there is a pending sync with the matching account and authority

public void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork)

Added in API level 1

Notify registered observers that a row was updated. To register, call ContentResolver.RegisterContentObserver(Uri,Boolean,Boolean). By default, CursorAdapter objects will get this notification. If syncToNetwork is true, this will attempt to schedule a local sync using the sync adapter that's registered for the authority of the provided uri. No account will be passed to the sync adapter, so all matching accounts will be synchronized.

Parameters
uri The uri of the content that was changed.
observer The observer that originated the change, may be null. The observer that originated the change will only receive the notification if it has requested to receive self-change notifications by implementing ContentObserver.DeliverSelfNotifications to return true.
syncToNetwork If true, attempt to sync the change to the network.
See Also

public void notifyChange(Uri uri, ContentObserver observer)

Added in API level 1

Notify registered observers that a row was updated and attempt to sync changes to the network. To register, call ContentResolver.RegisterContentObserver(Uri,Boolean,Boolean). By default, CursorAdapter objects will get this notification.

Parameters
uri The uri of the content that was changed.
observer The observer that originated the change, may be null. The observer that originated the change will only receive the notification if it has requested to receive self-change notifications by implementing ContentObserver.DeliverSelfNotifications to return true.

public final AssetFileDescriptoropenAssetFileDescriptor(Uri uri, String mode)

Added in API level 3

Open a raw file descriptor to access data under a URI. This interacts with the underlying ContentProvider.OpenAssetFile(Uri,String) method of the provider associated with the given URI, to retrieve any file stored there.

Accepts the following URI schemes:
The android.resource (ContentResolver.SchemeAndroidResource) 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

    java Example

    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

    java Example

    Uri uri = Uri.parse("android.resource://com.example.myapp/raw/my_resource");

Note that if this function is called for read-only input (mode is "r") on a content: URI, it will instead call ContentResolver.OpenTypedAssetFileDescriptor(Uri,String,String) for you with a MIME type of "*&#47;*". This allows such callers to benefit from any built-in data conversion that a provider implements.

Parameters
uri The desired URI to open.
mode The file mode to use, as per ContentProvider.OpenAssetFile(Uri,String).
Returns
  • Returns a new ParcelFileDescriptor pointing to the file. You own this descriptor and are responsible for closing it when done.
Throws
FileNotFoundExceptionThrows FileNotFoundException of no file exists under the URI or the mode is invalid.

public final AssetFileDescriptoropenAssetFileDescriptor(Uri uri, String mode, CancellationSignal cancellationSignal)

Added in API level 19

Open a raw file descriptor to access data under a URI. This interacts with the underlying ContentProvider.OpenAssetFile(Uri,String) method of the provider associated with the given URI, to retrieve any file stored there.

Accepts the following URI schemes:
The android.resource (ContentResolver.SchemeAndroidResource) 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

    java Example

    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

    java Example

    Uri uri = Uri.parse("android.resource://com.example.myapp/raw/my_resource");

Note that if this function is called for read-only input (mode is "r") on a content: URI, it will instead call ContentResolver.OpenTypedAssetFileDescriptor(Uri,String,String) for you with a MIME type of "*&#47;*". This allows such callers to benefit from any built-in data conversion that a provider implements.

Parameters
uri The desired URI to open.
mode The file mode to use, as per ContentProvider.OpenAssetFile(Uri,String).
cancellationSignal A signal to cancel the operation in progress, or null if none. If the operation is canceled, then OperationCanceledException will be thrown.
Returns
  • Returns a new ParcelFileDescriptor pointing to the file. You own this descriptor and are responsible for closing it when done.
Throws
FileNotFoundExceptionThrows FileNotFoundException of no file exists under the URI or the mode is invalid.

public final ParcelFileDescriptoropenFileDescriptor(Uri uri, String mode, CancellationSignal cancellationSignal)

Added in API level 19

Open a raw file descriptor to access data under a URI. This is like ContentResolver.OpenAssetFileDescriptor(Uri,String), but uses the underlying ContentProvider.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 ContentResolver.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 ContentResolver.OpenAssetFileDescriptor(Uri,String) for more information on these schemes.

If opening with the exclusive "r" or "w" modes, the returned ParcelFileDescriptor could be a pipe or socket pair to enable streaming of data. Opening with the "rw" mode implies a file on disk that supports seeking. If possible, always use an exclusive mode to give the underlying ContentProvider the most flexibility.

If you are writing a file, and need to communicate an error to the provider, use ParcelFileDescriptor.CloseWithError(String).

Parameters
uri The desired URI to open.
mode The file mode to use, as per ContentProvider.OpenFile(Uri,String).
cancellationSignal A signal to cancel the operation in progress, or null if none. If the operation is canceled, then OperationCanceledException will be thrown.
Returns
  • Returns a new ParcelFileDescriptor pointing to the file. You own this descriptor and are responsible for closing it when done.
Throws
FileNotFoundExceptionThrows FileNotFoundException if no file exists under the URI or the mode is invalid.
See Also

public final ParcelFileDescriptoropenFileDescriptor(Uri uri, String mode)

Added in API level 1

Open a raw file descriptor to access data under a URI. This is like ContentResolver.OpenAssetFileDescriptor(Uri,String), but uses the underlying ContentProvider.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 ContentResolver.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 ContentResolver.OpenAssetFileDescriptor(Uri,String) for more information on these schemes.

If opening with the exclusive "r" or "w" modes, the returned ParcelFileDescriptor could be a pipe or socket pair to enable streaming of data. Opening with the "rw" mode implies a file on disk that supports seeking. If possible, always use an exclusive mode to give the underlying ContentProvider the most flexibility.

If you are writing a file, and need to communicate an error to the provider, use ParcelFileDescriptor.CloseWithError(String).

Parameters
uri The desired URI to open.
mode The file mode to use, as per ContentProvider.OpenFile(Uri,String).
Returns
  • Returns a new ParcelFileDescriptor pointing to the file. You own this descriptor and are responsible for closing it when done.
Throws
FileNotFoundExceptionThrows FileNotFoundException if no file exists under the URI or the mode is invalid.
See Also

public final InputStreamopenInputStream(Uri uri)

Added in 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:

See ContentResolver.OpenAssetFileDescriptor(Uri,String) for more information on these schemes.

Parameters
uri The desired URI.
Returns
  • InputStream
Throws
FileNotFoundExceptionif the provided URI could not be opened.
See Also

public final OutputStreamopenOutputStream(Uri uri)

Added in API level 1

Synonym for ContentResolver.OpenOutputStream(Uri,String).

Throws
FileNotFoundExceptionif the provided URI could not be opened.

public final OutputStreamopenOutputStream(Uri uri, String mode)

Added in 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:

See ContentResolver.OpenAssetFileDescriptor(Uri,String) for more information on these schemes.

Parameters
uri The desired URI.
mode May be "w", "wa", "rw", or "rwt".
Returns
  • OutputStream
Throws
FileNotFoundExceptionif the provided URI could not be opened.
See Also

public final AssetFileDescriptoropenTypedAssetFileDescriptor(Uri uri, String mimeType, Bundle opts, CancellationSignal cancellationSignal)

Added in API level 19

Open a raw file descriptor to access (potentially type transformed) data from a "content:" URI. This interacts with the underlying ContentProvider.OpenTypedAssetFile(Uri,String,String) method of the provider associated with the given URI, to retrieve retrieve any appropriate data stream for the data stored there.

Unlike ContentResolver.OpenAssetFileDescriptor(Uri,String), this function only works with "content:" URIs, because content providers are the only facility with an associated MIME type to ensure that the returned data stream is of the desired type.

All text/* streams are encoded in UTF-8.

Parameters
uri The desired URI to open.
mimeType The desired MIME type of the returned data. This can be a pattern such as *&#47;*, which will allow the content provider to select a type, though there is no way for you to determine what type it is returning.
opts Additional provider-dependent options.
cancellationSignal A signal to cancel the operation in progress, or null if none. If the operation is canceled, then OperationCanceledException will be thrown.
Returns
  • Returns a new ParcelFileDescriptor from which you can read the data stream from the provider. Note that this may be a pipe, meaning you can't seek in it. The only seek you should do is if the AssetFileDescriptor contains an offset, to move to that offset before reading. You own this descriptor and are responsible for closing it when done.
Throws
FileNotFoundExceptionThrows FileNotFoundException of no data of the desired type exists under the URI.

public final AssetFileDescriptoropenTypedAssetFileDescriptor(Uri uri, String mimeType, Bundle opts)

Added in API level 11

Open a raw file descriptor to access (potentially type transformed) data from a "content:" URI. This interacts with the underlying ContentProvider.OpenTypedAssetFile(Uri,String,String) method of the provider associated with the given URI, to retrieve retrieve any appropriate data stream for the data stored there.

Unlike ContentResolver.OpenAssetFileDescriptor(Uri,String), this function only works with "content:" URIs, because content providers are the only facility with an associated MIME type to ensure that the returned data stream is of the desired type.

All text/* streams are encoded in UTF-8.

Parameters
uri The desired URI to open.
mimeType The desired MIME type of the returned data. This can be a pattern such as *&#47;*, which will allow the content provider to select a type, though there is no way for you to determine what type it is returning.
opts Additional provider-dependent options.
Returns
  • Returns a new ParcelFileDescriptor from which you can read the data stream from the provider. Note that this may be a pipe, meaning you can't seek in it. The only seek you should do is if the AssetFileDescriptor contains an offset, to move to that offset before reading. You own this descriptor and are responsible for closing it when done.
Throws
FileNotFoundExceptionThrows FileNotFoundException of no data of the desired type exists under the URI.

public final ICursorquery(Uri uri, String projection, String selection, String selectionArgs, String sortOrder)

Added in API level 1

Query the given URI, returning a ICursor 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
uri The URI, using the content:// scheme, for the content to retrieve.
projection A list of which columns to return. Passing null will return all columns, which is inefficient.
selection A 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.
selectionArgs You 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.
sortOrder How 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
See Also

public final ICursorquery(Uri uri, String projection, String selection, String selectionArgs, String sortOrder, CancellationSignal cancellationSignal)

Added in API level 16

Query the given URI, returning a ICursor over the result set with optional support for cancellation.

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
uri The URI, using the content:// scheme, for the content to retrieve.
projection A list of which columns to return. Passing null will return all columns, which is inefficient.
selection A 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.
selectionArgs You 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.
sortOrder How 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.
cancellationSignal A signal to cancel the operation in progress, or null if none. If the operation is canceled, then OperationCanceledException will be thrown when the query is executed.
Returns
  • A Cursor object, which is positioned before the first entry, or null
See Also

public final void registerContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer)

Added in API level 1

Register an observer class that gets callbacks when data identified by a given content URI changes.

Parameters
uri The URI to watch for changes. This can be a specific row URI, or a base URI for a whole class of content.
notifyForDescendents When false, the observer will be notified whenever a change occurs to the exact URI specified by uri or to one of the URI's ancestors in the path hierarchy. When true, the observer will also be notified whenever a change occurs to the URI's descendants in the path hierarchy.
observer The object that receives callbacks when changes occur.
See Also

public void releasePersistableUriPermission(Uri uri, int modeFlags)

Added in API level 19

Relinquish a persisted URI permission grant. The URI must have been previously made persistent with ContentResolver.TakePersistableUriPermission(Uri,ActivityFlags). Any non-persistent grants to the calling package will remain intact.

See Also

public static void removePeriodicSync(Account account, String authority, Bundle extras)

Added in API level 8

Remove a periodic sync. Has no affect if account, authority and extras don't match an existing periodic sync.

This method requires the caller to hold the permission Permission.WriteSyncSettings.

Parameters
account the account of the periodic sync to remove
authority the provider of the periodic sync to remove
extras the extras of the periodic sync to remove

public static void removeStatusChangeListener(Object handle)

Added in API level 5

Remove a previously registered status change listener.

Parameters
handle the handle that was returned by ContentResolver.AddStatusChangeListener(SyncObserverType,ISyncStatusObserver)

public static void requestSync(Account account, String authority, Bundle extras)

Added in 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
  • Account
  • null

Parameters
account which account should be synced
authority which authority should be synced
extras any extras to pass to the SyncAdapter.

public static void requestSync(SyncRequest request)

Added in API level 19

Register a sync with the SyncManager. These requests are built using the NoType:android/content/SyncRequest$Builder;Href=../../../reference/android/content/SyncRequest.Builder.html.

public static void setIsSyncable(Account account, String authority, int syncable)

Added in API level 5

Set whether this account/provider is syncable.

This method requires the caller to hold the permission Permission.WriteSyncSettings.

Parameters
syncable >0 denotes syncable, 0 means not syncable, <0 means unknown

public static void setMasterSyncAutomatically(boolean sync)

Added in 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.

This method requires the caller to hold the permission Permission.WriteSyncSettings.

Parameters
sync the master auto-sync setting that applies to all the providers and accounts

public static void setSyncAutomatically(Account account, String authority, boolean sync)

Added in API level 5

Set whether or not the provider is synced when it receives a network tickle.

This method requires the caller to hold the permission Permission.WriteSyncSettings.

Parameters
account the account whose setting we are querying
authority the provider whose behavior is being controlled
sync true if the provider should be synced when tickles are received for it

public void startSync(Uri uri, Bundle extras)

Added in API level 1

This method was deprecated in API level 5.
instead use ContentResolver.RequestSync(Account,String,String)

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
  • Account
  • null

Parameters
uri the uri of the provider to sync or null to sync all providers.
extras any extras to pass to the SyncAdapter.

public void takePersistableUriPermission(Uri uri, int modeFlags)

Added in API level 19

Take a persistable URI permission grant that has been offered. Once taken, the permission grant will be remembered across device reboots. Only URI permissions granted with Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION can be persisted. If the grant has already been persisted, taking it again will touch UriPermission.PersistedTime.

See Also

public final Uriuncanonicalize(Uri url)

Added in API level 19

Given a canonical Uri previously generated by ContentResolver.Canonicalize(Uri), convert it to its local non-canonical form. This can be useful in some cases where you know that you will only be using the Uri in the current environment and want to avoid any possible overhead when using it with the content provider or want to verify that the referenced data exists at all in the new environment.

Parameters
url The canonical Uri that is to be convered back to its non-canonical form.
Returns
  • Returns the non-canonical representation of url. This will return null if data identified by the canonical Uri can not be found in the current environment; callers must always check for null and deal with that by appropriately falling back to an alternative.
See Also

public final void unregisterContentObserver(ContentObserver observer)

Added in API level 1

Unregisters a change observer.

Parameters
observer The previously registered observer that is no longer needed.
See Also

public final int update(Uri uri, ContentValues values, String where, String selectionArgs)

Added in API level 1

Update row(s) in a content URI. If the content provider supports transactions the update will be atomic.

Parameters
uri The URI to modify.
values The new field values. The key is the column name for the field. A null value will remove an existing field value.
where A filter to apply to rows before updating, formatted as an SQL WHERE clause (excluding the WHERE itself).
Returns
  • the number of rows updated.
Throws
NullPointerExceptionif uri or values are null

public static void validateSyncExtrasBundle(Bundle extras)

Added in API level 1

Check that only values of the following types are in the Bundle:

  • Integer
  • Long
  • Boolean
  • Float
  • Double
  • String
  • Account
  • null

Parameters
extras the Bundle to check

[Android Documentation]

Requirements

Namespace: Android.Content
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Content.ContentResolver are listed below.

See Also: Object

Public Constructors

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Fields

const
AnyCursorItemTypeString. This is the Android platform's generic MIME type to match any MIME type of the form "ContentResolver.CursorItemBaseType/SUB_TYPE".
const
CursorDirBaseTypeString. This is the Android platform's base MIME type for a content: URI containing a Cursor of zero or more items.
const
CursorItemBaseTypeString. This is the Android platform's base MIME type for a content: URI containing a Cursor of a single item.
const
ExtraSizeString. An extra Point describing the optimal size for a requested image resource, in pixels.
const
SchemeAndroidResourceString.
const
SchemeContentString.
const
SchemeFileString.
const
SyncExtrasAccountString.
const
SyncExtrasDiscardLocalDeletionsString. Indicates that the sync adapter should not proceed with the delete operations, if it determines that there are too many.
const
SyncExtrasDoNotRetryString. If this extra is set to true then the request will not be retried if it fails.
const
SyncExtrasExpeditedString. If this extra is set to true, the sync request will be scheduled at the front of the sync request queue and without any delay
const
SyncExtrasForceString.
const
SyncExtrasIgnoreBackoffString. 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.
const
SyncExtrasIgnoreSettingsString. If this extra is set to true then the sync settings (like getSyncAutomatically()) are ignored by the sync scheduler.
const
SyncExtrasInitializeString. Set by the SyncManager to request that the SyncAdapter initialize itself for the given account/authority pair.
const
SyncExtrasManualString. Setting this extra is the equivalent of setting both ContentResolver.SyncExtrasIgnoreSettings and ContentResolver.SyncExtrasIgnoreBackoff
const
SyncExtrasOverrideTooManyDeletionsString. Indicates that the sync adapter should proceed with the delete operations, even if it determines that there are too many.
const
SyncExtrasUploadString. Indicates that this sync is intended to only upload local changes to the server.
const
SyncObserverTypeActiveSyncObserverType (4).
const
SyncObserverTypePendingSyncObserverType (2).
const
SyncObserverTypeSettingsSyncObserverType (1).

Public Properties

[read-only]
static
CurrentSyncSyncInfo. If a sync is active returns the information about it, otherwise returns null.
[read-only]
static
CurrentSyncsIList<SyncInfo>. Returns a list with information about all the active syncs.
static
MasterSyncAutomaticallyBoolean. Gets the master auto-sync setting that applies to all the providers and accounts.
[read-only]
OutgoingPersistedUriPermissionsIList<UriPermission>. Return list of all persisted URI permission grants that are hosted by the calling app.
[read-only]
PersistedUriPermissionsIList<UriPermission>. Return list of all URI permission grants that have been persisted by the calling app.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

AcquireContentProviderClient(Uri) : ContentProviderClient
Returns a ContentProviderClient that is associated with the ContentProvider that services the content at uri, starting the provider if necessary.
AcquireContentProviderClient(String) : ContentProviderClient
Returns a ContentProviderClient that is associated with the ContentProvider with the authority of name, starting the provider if necessary.
AcquireUnstableContentProviderClient(Uri) : ContentProviderClient
Like ContentResolver.AcquireContentProviderClient(Uri), but for use when you do not trust the stability of the target content provider.
AcquireUnstableContentProviderClient(String) : ContentProviderClient
Like ContentResolver.AcquireContentProviderClient(String), but for use when you do not trust the stability of the target content provider.
static
AddPeriodicSync(Account, String, Bundle, Int64)
Specifies that a sync should be requested with the specified the account, authority, and extras at the given frequency.
static
AddStatusChangeListener(SyncObserverType, ISyncStatusObserver) : Object
Request notifications when the different aspects of the SyncManager change.
ApplyBatch(String, IList<ContentProviderOperation>) : ContentProviderResult[]
BulkInsert(Uri, ContentValues[]) : Int32
Inserts multiple rows into a table at the given URL.
Call(Uri, String, String, Bundle) : Bundle
Call a provider-defined method.
static
CancelSync(SyncRequest)
Remove the specified sync.
CancelSync(Uri)
Cancel any active or pending syncs that match the Uri.
static
CancelSync(Account, String)
Cancel any active or pending syncs that match account and authority.
Canonicalize(Uri) : Uri
Transform the given url to a canonical representation of its referenced resource, which can be used across devices, persisted, backed up and restored, etc.
Delete(Uri, String, String[]) : Int32
Deletes row(s) specified by a content URI.
static
GetIsSyncable(Account, String) : Int32
Check if this account/provider is syncable.
static
GetPeriodicSyncs(Account, String) : IList<PeriodicSync>
Get the list of information about the periodic syncs for the given account and authority.
GetStreamTypes(Uri, String) : String[]
Query for the possible MIME types for the representations the given content URL can be returned when opened as as stream with ContentResolver.OpenTypedAssetFileDescriptor(Uri,String,String).
static
GetSyncAdapterTypes() : SyncAdapterType[]
Get information about the SyncAdapters that are known to the system.
static
GetSyncAutomatically(Account, String) : Boolean
Check if the provider should be synced when a network tickle is received
GetType(Uri) : String
Return the MIME type of the given content URL.
Insert(Uri, ContentValues) : Uri
Inserts a row into a table at the given URL.
static
IsSyncActive(Account, String) : Boolean
Returns true if there is currently a sync operation for the given account or authority actively being processed.
static
IsSyncPending(Account, String) : Boolean
Return true if the pending status is true of any matching authorities.
NotifyChange(Uri, ContentObserver)
Notify registered observers that a row was updated and attempt to sync changes to the network.
NotifyChange(Uri, ContentObserver, Boolean)
Notify registered observers that a row was updated.
OpenAssetFileDescriptor(Uri, String) : AssetFileDescriptor
Open a raw file descriptor to access data under a URI.
OpenAssetFileDescriptor(Uri, String, CancellationSignal) : AssetFileDescriptor
Open a raw file descriptor to access data under a URI.
OpenFileDescriptor(Uri, String) : ParcelFileDescriptor
Open a raw file descriptor to access data under a URI.
OpenFileDescriptor(Uri, String, CancellationSignal) : ParcelFileDescriptor
Open a raw file descriptor to access data under a URI.
OpenInputStream(Uri) : Stream
Open a stream on to the content associated with a content URI.
OpenOutputStream(Uri) : Stream
Synonym for ContentResolver.OpenOutputStream(Uri,String).
OpenOutputStream(Uri, String) : Stream
Open a stream on to the content associated with a content URI.
OpenTypedAssetFileDescriptor(Uri, String, Bundle) : AssetFileDescriptor
Open a raw file descriptor to access (potentially type transformed) data from a "content:" URI.
OpenTypedAssetFileDescriptor(Uri, String, Bundle, CancellationSignal) : AssetFileDescriptor
Open a raw file descriptor to access (potentially type transformed) data from a "content:" URI.
Query(Uri, String[], String, String[], String) : ICursor
Query the given URI, returning a ICursor over the result set.
Query(Uri, String[], String, String[], String, CancellationSignal) : ICursor
Query the given URI, returning a ICursor over the result set with optional support for cancellation.
RegisterContentObserver(Uri, Boolean, ContentObserver)
Register an observer class that gets callbacks when data identified by a given content URI changes.
ReleasePersistableUriPermission(Uri, ActivityFlags)
Relinquish a persisted URI permission grant.
static
RemovePeriodicSync(Account, String, Bundle)
Remove a periodic sync.
static
RemoveStatusChangeListener(Object)
Remove a previously registered status change listener.
static
RequestSync(SyncRequest)
Register a sync with the SyncManager.
static
RequestSync(Account, String, Bundle)
Start an asynchronous sync operation.
static
SetIsSyncable(Account, String, Int32)
Set whether this account/provider is syncable.
static
SetSyncAutomatically(Account, String, Boolean)
Set whether or not the provider is synced when it receives a network tickle.
StartSync(Uri, Bundle)
Start an asynchronous sync operation.
TakePersistableUriPermission(Uri, ActivityFlags)
Take a persistable URI permission grant that has been offered.
Uncanonicalize(Uri) : Uri
Given a canonical Uri previously generated by ContentResolver.Canonicalize(Uri), convert it to its local non-canonical form.
UnregisterContentObserver(ContentObserver)
Unregisters a change observer.
Update(Uri, ContentValues, String, String[]) : Int32
Update row(s) in a content URI.
static
ValidateSyncExtrasBundle(Bundle)
Check that only values of the following types are in the Bundle:
  • Integer
  • Long
  • Boolean
  • Float
  • Double
  • String
  • Account
  • null