Android.Content.ContentProvider Class
Content providers are one of the primary building blocks of Android applications, providing content to applications.

See Also: ContentProvider Members

Syntax

[Android.Runtime.Register("android/content/ContentProvider", DoNotGenerateAcw=true)]
public abstract class ContentProvider : Java.Lang.Object, IComponentCallbacks2, IDisposable

Remarks

Content providers are one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single Android.Content.ContentResolver interface. A content provider is only required if you need to share data between multiple applications. For example, the contacts data is used by multiple applications and must be stored in a content provider. If you don't need to share data amongst multiple applications you can use a database directly via Android.Database.Sqlite.SQLiteDatabase.

When a request is made via a Android.Content.ContentResolver the system inspects the authority of the given URI and passes the request to the content provider registered with the authority. The content provider can interpret the rest of the URI however it wants. The Android.Content.UriMatcher class is helpful for parsing URIs.

The primary methods that need to be implemented are:

Data access methods (such as ContentProvider.Insert(Android.Net.Uri, Android.Content.ContentValues) and ContentProvider.Update(Android.Net.Uri, Android.Content.ContentValues, Android.Content.ContentValues, Android.Content.ContentValues)) may be called from many threads at once, and must be thread-safe. Other methods (such as ContentProvider.OnCreate) are only called from the application main thread, and must avoid performing lengthy operations. See the method descriptions for their expected thread behavior.

Requests to Android.Content.ContentResolver are automatically forwarded to the appropriate ContentProvider instance, so subclasses don't have to worry about the details of cross-process calls.

Developer Guides

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

Summary

Nested Classes
interfaceNoType:android/content/ContentProvider$PipeDataWriter;Href=../../../reference/android/content/ContentProvider.PipeDataWriter.html<T> Interface to write a stream of data to a pipe. 
Inherited Constants
From interface Android.Content.ComponentCallbacks2
intComponentCallbacks2.TrimMemoryBackground Level for ComponentCallbacks2.onTrimMemory(int): the process has gone on to the LRU list.
intComponentCallbacks2.TrimMemoryComplete Level for ComponentCallbacks2.onTrimMemory(int): the process is nearing the end of the background LRU list, and if more memory isn't found soon it will be killed.
intComponentCallbacks2.TrimMemoryModerate Level for ComponentCallbacks2.onTrimMemory(int): the process is around the middle of the background LRU list; freeing memory can help the system keep other processes running later in the list for better overall performance.
intComponentCallbacks2.TrimMemoryRunningCritical Level for ComponentCallbacks2.onTrimMemory(int): the process is not an expendable background process, but the device is running extremely low on memory and is about to not be able to keep any background processes running.
intComponentCallbacks2.TrimMemoryRunningLow Level for ComponentCallbacks2.onTrimMemory(int): the process is not an expendable background process, but the device is running low on memory.
intComponentCallbacks2.TrimMemoryRunningModerate Level for ComponentCallbacks2.onTrimMemory(int): the process is not an expendable background process, but the device is running moderately low on memory.
intComponentCallbacks2.TrimMemoryUiHidden Level for ComponentCallbacks2.onTrimMemory(int): the process had been showing a user interface, and is no longer doing so.
Public Constructors
ContentProvider() Construct a ContentProvider instance.
Public Methods
Android.Content.ContentProviderResultContentProvider.applyBatch(java.util.ArrayList<android.content.ContentProviderOperation>)(Android.Runtime.JavaList<Android.Content.ContentProviderOperation> operations) Override this to handle requests to perform a batch of operations, or the default implementation will iterate over the operations and call ContentProviderOperation.Apply(ContentProvider, Android.Content.ContentProviderResult[], Android.Content.ContentProviderResult[]) on each of them.
voidContentProvider.AttachInfo(Context, Android.Content.PM.ProviderInfo)(Android.Content.Context context, Android.Content.PM.ProviderInfo info) After being instantiated, this is called to tell the content provider about itself.
intContentProvider.BulkInsert(Android.Net.Uri, Android.Content.ContentValues[])(Android.Net.Uri uri, Android.Content.ContentValues values) Override this to handle requests to insert a set of new rows, or the default implementation will iterate over the values and call ContentProvider.Insert(Android.Net.Uri, Android.Content.ContentValues) on each of them.
Android.OS.BundleContentProvider.Call(string, System.String, System.String)(Java.Lang.String method, Java.Lang.String arg, Android.OS.Bundle extras) Call a provider-defined method.
Android.Net.UriContentProvider.Canonicalize(Android.Net.Uri)(Android.Net.Uri url) Implement this to support canonicalization of URIs that refer to your content provider.
abstract intContentProvider.Delete(Android.Net.Uri, System.String, System.String)(Android.Net.Uri uri, Java.Lang.String selection, Java.Lang.String selectionArgs) Implement this to handle requests to delete one or more rows.
voidContentProvider.Dump(Java.IO.FileDescriptor, Java.IO.PrintWriter, Java.IO.PrintWriter)(Java.IO.FileDescriptor fd, Java.IO.PrintWriter writer, Java.Lang.String args) Print the Provider's state into the given stream.
final Java.Lang.StringContentProvider.CallingPackage() Return the package name of the caller that initiated the request being processed on the current thread.
final Android.Content.ContextContentProvider.Context() Retrieves the Context this provider is running in.
final Android.Content.PM.PathPermissionContentProvider.GetPathPermissions() Return the path-based permissions required for read and/or write access to this content provider.
final Java.Lang.StringContentProvider.ReadPermission() Return the name of the permission required for read-only access to this content provider.
Java.Lang.StringContentProvider.GetStreamTypes(Android.Net.Uri, System.String)(Android.Net.Uri uri, Java.Lang.String mimeTypeFilter) Called by a client to determine the types of data streams that this content provider supports for the given URI.
abstract Java.Lang.StringContentProvider.GetType(Android.Net.Uri)(Android.Net.Uri uri) Implement this to handle requests for the MIME type of the data at the given URI.
final Java.Lang.StringContentProvider.WritePermission() Return the name of the permission required for read/write access to this content provider.
abstract Android.Net.UriContentProvider.Insert(Android.Net.Uri, Android.Content.ContentValues)(Android.Net.Uri uri, Android.Content.ContentValues values) Implement this to handle requests to insert a new row.
voidContentProvider.OnConfigurationChanged(Android.Content.Res.Configuration)(Android.Content.Res.Configuration newConfig) Called by the system when the device configuration changes while your component is running. This method is always called on the application main thread, and must not perform lengthy operations.
abstract booleanContentProvider.OnCreate() Implement this to initialize your content provider on startup.
voidContentProvider.OnLowMemory() This is called when the overall system is running low on memory, and actively running processes should trim their memory usage. This method is always called on the application main thread, and must not perform lengthy operations.
voidContentProvider.OnTrimMemory(TrimMemory)(int level) Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.
Android.Content.Res.AssetFileDescriptorContentProvider.OpenAssetFile(Android.Net.Uri, System.String, System.String)(Android.Net.Uri uri, Java.Lang.String mode, Android.OS.CancellationSignal signal) This is like ContentProvider.OpenFile(Android.Net.Uri, System.String), but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .apk.
Android.Content.Res.AssetFileDescriptorContentProvider.OpenAssetFile(Android.Net.Uri, System.String)(Android.Net.Uri uri, Java.Lang.String mode) This is like ContentProvider.OpenFile(Android.Net.Uri, System.String), but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .apk.
Android.OS.ParcelFileDescriptorContentProvider.OpenFile(Android.Net.Uri, System.String)(Android.Net.Uri uri, Java.Lang.String mode) Override this to handle requests to open a file blob.
Android.OS.ParcelFileDescriptorContentProvider.OpenFile(Android.Net.Uri, System.String, System.String)(Android.Net.Uri uri, Java.Lang.String mode, Android.OS.CancellationSignal signal) Override this to handle requests to open a file blob.
<T> Android.OS.ParcelFileDescriptorContentProvider.openPipeHelper(android.net.Uri, java.lang.String, android.os.Bundle, T, android.content.ContentProvider.PipeDataWriter<T>)(Android.Net.Uri uri, Java.Lang.String mimeType, Android.OS.Bundle opts, T args, NoType:android/content/ContentProvider$PipeDataWriter;Href=../../../reference/android/content/ContentProvider.PipeDataWriter.html<T> func) A helper function for implementing ContentProvider.OpenTypedAssetFile(Android.Net.Uri, System.String, System.String), for creating a data pipe and background thread allowing you to stream generated data back to the client.
Android.Content.Res.AssetFileDescriptorContentProvider.OpenTypedAssetFile(Android.Net.Uri, System.String, System.String)(Android.Net.Uri uri, Java.Lang.String mimeTypeFilter, Android.OS.Bundle opts) Called by a client to open a read-only stream containing data of a particular MIME type.
Android.Content.Res.AssetFileDescriptorContentProvider.OpenTypedAssetFile(Android.Net.Uri, System.String, System.String, System.String)(Android.Net.Uri uri, Java.Lang.String mimeTypeFilter, Android.OS.Bundle opts, Android.OS.CancellationSignal signal) Called by a client to open a read-only stream containing data of a particular MIME type.
abstract Android.Database.ICursorContentProvider.Query(Android.Net.Uri, System.String[], System.String[], System.String[], System.String[])(Android.Net.Uri uri, Java.Lang.String projection, Java.Lang.String selection, Java.Lang.String selectionArgs, Java.Lang.String sortOrder) Implement this to handle query requests from clients.
Android.Database.ICursorContentProvider.Query(Android.Net.Uri, System.String[], System.String[], System.String[], System.String[], System.String[])(Android.Net.Uri uri, Java.Lang.String projection, Java.Lang.String selection, Java.Lang.String selectionArgs, Java.Lang.String sortOrder, Android.OS.CancellationSignal cancellationSignal) Implement this to handle query requests from clients with support for cancellation.
voidContentProvider.Shutdown() Implement this to shut down the ContentProvider instance.
Android.Net.UriContentProvider.Uncanonicalize(Android.Net.Uri)(Android.Net.Uri url) Remove canonicalization from canonical URIs previously returned by ContentProvider.Canonicalize(Android.Net.Uri).
abstract intContentProvider.Update(Android.Net.Uri, Android.Content.ContentValues, Android.Content.ContentValues, Android.Content.ContentValues)(Android.Net.Uri uri, Android.Content.ContentValues values, Java.Lang.String selection, Java.Lang.String selectionArgs) Implement this to handle requests to update one or more rows.
Protected Methods
booleanContentProvider.IsTemporary() Returns true if this instance is a temporary content provider.
final Android.OS.ParcelFileDescriptorContentProvider.OpenFileHelper(Android.Net.Uri, System.String)(Android.Net.Uri uri, Java.Lang.String mode) Convenience for subclasses that wish to implement ContentProvider.OpenFile(Android.Net.Uri, System.String) by looking up a column named "_data" at the given URI.
final voidContentProvider.SetPathPermissions(Android.Content.PM.PathPermission[])(Android.Content.PM.PathPermission permissions) Change the path-based permission required to read and/or write data in the content provider.
final voidContentProvider.ReadPermission(Java.Lang.String permission) Change the permission required to read data from the content provider.
final voidContentProvider.WritePermission(Java.Lang.String permission) Change the permission required to read and write data in the content provider.
Inherited Methods
From class Java.Lang.Object
Java.Lang.ObjectJava.Lang.Object.Clone() Creates and returns a copy of this Object.
booleanJava.Lang.Object.Equals(Java.Lang.Object)(Java.Lang.Object o) Compares this instance with the specified object and indicates if they are equal.
voidJava.Lang.Object.JavaFinalize() Invoked when the garbage collector has detected that this instance is no longer reachable.
final Java.Lang.Class<?>Java.Lang.Object.Class() Returns the unique instance of Java.Lang.Class that represents this object's class.
intJava.Lang.Object.GetHashCode() Returns an integer hash code for this object.
final voidJava.Lang.Object.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 voidJava.Lang.Object.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.
Java.Lang.StringJava.Lang.Object.ToString() Returns a string containing a concise, human-readable description of this object.
final voidJava.Lang.Object.Wait() Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
final voidJava.Lang.Object.Wait(long, System.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 voidJava.Lang.Object.Wait(long)(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.
From interface Android.Content.IComponentCallbacks
abstract voidIComponentCallbacks.OnConfigurationChanged(Android.Content.Res.Configuration)(Android.Content.Res.Configuration newConfig) Called by the system when the device configuration changes while your component is running.
abstract voidIComponentCallbacks.OnLowMemory() This is called when the overall system is running low on memory, and actively running processes should trim their memory usage.
From interface Android.Content.ComponentCallbacks2
abstract voidComponentCallbacks2.onTrimMemory(int)(int level) Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.

Public Constructors

public ContentProvider()

Added in API level 1

Construct a ContentProvider instance. Content providers must be declared in the manifest, accessed with Android.Content.ContentResolver, and created automatically by the system, so applications usually do not create ContentProvider instances directly.

At construction time, the object is uninitialized, and most fields and methods are unavailable. Subclasses should initialize themselves in ContentProvider.OnCreate, not the constructor.

Content providers are created on the application main thread at application launch time. The constructor must not perform lengthy operations, or application startup will be delayed.

Public Methods

public Android.Content.ContentProviderResultapplyBatch(Android.Runtime.JavaList<Android.Content.ContentProviderOperation> operations)

Added in API level 5

Override this to handle requests to perform a batch of operations, or the default implementation will iterate over the operations and call ContentProviderOperation.Apply(ContentProvider, Android.Content.ContentProviderResult[], Android.Content.ContentProviderResult[]) on each of them. If all calls to ContentProviderOperation.Apply(ContentProvider, Android.Content.ContentProviderResult[], Android.Content.ContentProviderResult[]) succeed then a Android.Content.ContentProviderResult array with as many elements as there were operations will be returned. If any of the calls fail, it is up to the implementation how many of the others take effect. This method can be called from multiple threads, as described in Processes and Threads.

Parameters
operations the operations to apply
Returns
Throws
Android.Content.OperationApplicationExceptionthrown if any operation fails.
See Also

public void attachInfo(Android.Content.Context context, Android.Content.PM.ProviderInfo info)

Added in API level 1

After being instantiated, this is called to tell the content provider about itself.

Parameters
context The context this provider is running in
info Registered information about this content provider

public int bulkInsert(Android.Net.Uri uri, Android.Content.ContentValues values)

Added in API level 1

Override this to handle requests to insert a set of new rows, or the default implementation will iterate over the values and call ContentProvider.Insert(Android.Net.Uri, Android.Content.ContentValues) on each of them. As a courtesy, call ContentResolver.NotifyChange(Android.Net.Uri, Android.Database.ContentObserver) after inserting. This method can be called from multiple threads, as described in Processes and Threads.

Parameters
uri The content:// URI of the insertion request.
values An array of sets of column_name/value pairs to add to the database. This must not be null.
Returns

public Android.OS.Bundlecall(Java.Lang.String method, Java.Lang.String arg, Android.OS.Bundle extras)

Added in API level 11

Call a provider-defined method. This can be used to implement interfaces that are cheaper and/or unnatural for a table-like model.

WARNING: The framework does no permission checking on this entry into the content provider besides the basic ability for the application to get access to the provider at all. For example, it has no idea whether the call being executed may read or write data in the provider, so can't enforce those individual permissions. Any implementation of this method must do its own permission checks on incoming calls to make sure they are allowed.

Parameters
method method name to call. Opaque to framework, but should not be null.
arg provider-defined String argument. May be null.
extras provider-defined Bundle argument. May be null.
Returns

public Android.Net.Uricanonicalize(Android.Net.Uri url)

Added in API level 19

Implement this to support canonicalization of URIs that refer to your content provider. A canonical URI is one that can be transported across devices, backup/restore, and other contexts, and still be able to refer to the same data item. Typically this is implemented by adding query params to the URI allowing the content provider to verify that an incoming canonical URI references the same data as it was originally intended for and, if it doesn't, to find that data (if it exists) in the current environment.

For example, if the content provider holds people and a normal URI in it is created with a row index into that people database, the cananical representation may have an additional query param at the end which specifies the name of the person it is intended for. Later calls into the provider with that URI will look up the row of that URI's base index and, if it doesn't match or its entry's name doesn't match the name in the query param, perform a query on its database to find the correct row to operate on.

If you implement support for canonical URIs, all incoming calls with URIs (including this one) must perform this verification and recovery of any canonical URIs they receive. In addition, you must also implement ContentProvider.Uncanonicalize(Android.Net.Uri) to strip the canonicalization of any of these URIs.

The default implementation of this method returns null, indicating that canonical URIs are not supported.

Parameters
url The Uri to canonicalize.
Returns

public abstract int delete(Android.Net.Uri uri, Java.Lang.String selection, Java.Lang.String selectionArgs)

Added in API level 1

Implement this to handle requests to delete one or more rows. The implementation should apply the selection clause when performing deletion, allowing the operation to affect multiple rows in a directory. As a courtesy, call ContentResolver.NotifyChange(Android.Net.Uri, Android.Database.ContentObserver) after deleting. This method can be called from multiple threads, as described in Processes and Threads.

The implementation is responsible for parsing out a row ID at the end of the URI, if a specific row is being deleted. That is, the client would pass in content://contacts/people/22 and the implementation is responsible for parsing the record number (22) when creating a SQL statement.

Parameters
uri The full URI to query, including a row ID (if a specific record is requested).
selection An optional restriction to apply to rows when deleting.
Returns
Throws
Android.Database.SQLException

public void dump(Java.IO.FileDescriptor fd, Java.IO.PrintWriter writer, Java.Lang.String args)

Added in API level 18

Print the Provider's state into the given stream. This gets invoked if you run "adb shell dumpsys activity provider <provider_component_name>".

Parameters
fd The raw file descriptor that the dump is being sent to.
writer The PrintWriter to which you should dump your state. This will be closed for you after you return.
args additional arguments to the dump request.

public final Java.Lang.StringgetCallingPackage()

Added in API level 19

Return the package name of the caller that initiated the request being processed on the current thread. The returned package will have been verified to belong to the calling UID. Returns null if not currently processing a request.

This will always return null when processing ContentProvider.GetType(Android.Net.Uri) or ContentProvider.GetStreamTypes(Android.Net.Uri, System.String) requests.

Throws
Java.Lang.SecurityExceptionif the calling package doesn't belong to the calling UID.
See Also

public final Android.Content.ContextgetContext()

Added in API level 1

Retrieves the Context this provider is running in. Only available once ContentProvider.OnCreate has been called -- this will return null in the constructor.

public final Android.Content.PM.PathPermissiongetPathPermissions()

Added in API level 4

Return the path-based permissions required for read and/or write access to this content provider. This method can be called from multiple threads, as described in Processes and Threads.

public final Java.Lang.StringgetReadPermission()

Added in API level 1

Return the name of the permission required for read-only access to this content provider. This method can be called from multiple threads, as described in Processes and Threads.

public Java.Lang.StringgetStreamTypes(Android.Net.Uri uri, Java.Lang.String mimeTypeFilter)

Added in API level 11

Called by a client to determine the types of data streams that this content provider supports for the given URI. The default implementation returns null, meaning no types. If your content provider stores data of a particular type, return that MIME type if it matches the given mimeTypeFilter. If it can perform type conversions, return an array of all supported MIME types that match mimeTypeFilter.

Parameters
uri The data in the content provider being queried.
mimeTypeFilter The type of data the client desires. May be a pattern, such as *&#47;* to retrieve all possible data types.
Returns
See Also

public abstract Java.Lang.StringgetType(Android.Net.Uri uri)

Added in API level 1

Implement this to handle requests for the MIME type of the data at the given URI. The returned MIME type should start with vnd.android.cursor.item for a single record, or vnd.android.cursor.dir/ for multiple items. This method can be called from multiple threads, as described in Processes and Threads.

Note that there are no permissions needed for an application to access this information; if your content provider requires read and/or write permissions, or is not exported, all applications can still call this method regardless of their access permissions. This allows them to retrieve the MIME type for a URI when dispatching intents.

Parameters
uri the URI to query.
Returns

public final Java.Lang.StringgetWritePermission()

Added in API level 1

Return the name of the permission required for read/write access to this content provider. This method can be called from multiple threads, as described in Processes and Threads.

public abstract Android.Net.Uriinsert(Android.Net.Uri uri, Android.Content.ContentValues values)

Added in API level 1

Implement this to handle requests to insert a new row. As a courtesy, call ContentResolver.NotifyChange(Android.Net.Uri, Android.Database.ContentObserver) after inserting. This method can be called from multiple threads, as described in Processes and Threads.

Parameters
uri The content:// URI of the insertion request. This must not be null.
values A set of column_name/value pairs to add to the database. This must not be null.
Returns

public void onConfigurationChanged(Android.Content.Res.Configuration newConfig)

Added in API level 1

Called by the system when the device configuration changes while your component is running. Note that, unlike activities, other components are never restarted when a configuration changes: they must always deal with the results of the change, such as by re-retrieving resources.

At the time that this function has been called, your Resources object will have been updated to return resource values matching the new configuration.

For more information, read Handling Runtime Changes. This method is always called on the application main thread, and must not perform lengthy operations.

The default content provider implementation does nothing. Override this method to take appropriate action. (Content providers do not usually care about things like screen orientation, but may want to know about locale changes.)

Parameters
newConfig The new device configuration.

public abstract boolean onCreate()

Added in API level 1

Implement this to initialize your content provider on startup. This method is called for all registered content providers on the application main thread at application launch time. It must not perform lengthy operations, or application startup will be delayed.

You should defer nontrivial initialization (such as opening, upgrading, and scanning databases) until the content provider is used (via ContentProvider.Query(Android.Net.Uri, System.String[], System.String[], System.String[], System.String[]), ContentProvider.Insert(Android.Net.Uri, Android.Content.ContentValues), etc). Deferred initialization keeps application startup fast, avoids unnecessary work if the provider turns out not to be needed, and stops database errors (such as a full disk) from halting application launch.

If you use SQLite, Android.Database.Sqlite.SQLiteOpenHelper is a helpful utility class that makes it easy to manage databases, and will automatically defer opening until first use. If you do use SQLiteOpenHelper, make sure to avoid calling Android.Database.Sqlite.SQLiteOpenHelper.ReadableDatabase or Android.Database.Sqlite.SQLiteOpenHelper.WritableDatabase from this method. (Instead, override Android.Database.Sqlite.SQLiteOpenHelper.OnOpen(Android.Database.Sqlite.SQLiteDatabase) to initialize the database when it is first opened.)

Returns

public void onLowMemory()

Added in API level 1

This is called when the overall system is running low on memory, and actively running processes should trim their memory usage. While the exact point at which this will be called is not defined, generally it will happen when all background process have been killed. That is, before reaching the point of killing processes hosting service and foreground UI that we would like to avoid killing.

You should implement this method to release any caches or other unnecessary resources you may be holding on to. The system will perform a garbage collection for you after returning from this method.

Preferably, you should implement ComponentCallbacks2.onTrimMemory(int) from Android.Content.ComponentCallbacks2 to incrementally unload your resources based on various levels of memory demands. That API is available for API level 14 and higher, so you should only use this IComponentCallbacks.OnLowMemory method as a fallback for older versions, which can be treated the same as ComponentCallbacks2.onTrimMemory(int) with the ComponentCallbacks2.TrimMemoryComplete level.

This method is always called on the application main thread, and must not perform lengthy operations.

The default content provider implementation does nothing. Subclasses may override this method to take appropriate action.

public void onTrimMemory(int level)

Added in API level 14

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. This will happen for example when it goes in the background and there is not enough memory to keep as many background processes running as desired. You should never compare to exact values of the level, since new intermediate values may be added -- you will typically want to compare if the value is greater or equal to a level you are interested in.

To retrieve the processes current trim level at any point, you can use Android.App.ActivityManager.GetMyMemoryState(.RunningAppProcessInfo).

Parameters
level The context of the trim, giving a hint of the amount of trimming the application may like to perform. May be ComponentCallbacks2.TrimMemoryComplete, ComponentCallbacks2.TrimMemoryModerate, ComponentCallbacks2.TrimMemoryBackground, ComponentCallbacks2.TrimMemoryUiHidden, ComponentCallbacks2.TrimMemoryRunningCritical, ComponentCallbacks2.TrimMemoryRunningLow, or ComponentCallbacks2.TrimMemoryRunningModerate.

public Android.Content.Res.AssetFileDescriptoropenAssetFile(Android.Net.Uri uri, Java.Lang.String mode, Android.OS.CancellationSignal signal)

Added in API level 19

This is like ContentProvider.OpenFile(Android.Net.Uri, System.String), but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .apk. This method can be called from multiple threads, as described in Processes and Threads.

If you implement this, your clients must be able to deal with such file slices, either directly with ContentResolver.OpenAssetFileDescriptor(Android.Net.Uri, System.String), or by using the higher-level ContentResolver.OpenInputStream(Android.Net.Uri) or ContentResolver.OpenOutputStream(Android.Net.Uri) methods.

The returned AssetFileDescriptor can be a pipe or socket pair to enable streaming of data.

If you are implementing this to return a full file, you should create the AssetFileDescriptor with Android.Content.Res.AssetFileDescriptor.UnknownLength to be compatible with applications that cannot handle sub-sections of files.

For use in Intents, you will want to implement ContentProvider.GetType(Android.Net.Uri) to return the appropriate MIME type for the data returned here with the same URI. This will allow intent resolution to automatically determine the data MIME type and select the appropriate matching targets as part of its operation.

For better interoperability with other applications, it is recommended that for any URIs that can be opened, you also support queries on them containing at least the columns specified by Android.Provider.OpenableColumns.

Parameters
uri The URI whose file is to be opened.
mode Access mode for the file. May be "r" for read-only access, "w" for write-only access (erasing whatever data is currently in the file), "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data, and "rwt" for read and write access that truncates any existing file.
signal A signal to cancel the operation in progress, or null if none. For example, if you are downloading a file from the network to service a "rw" mode request, you should periodically call Android.OS.CancellationSignal.ThrowIfCanceled to check whether the client has canceled the request and abort the download.
Returns
Throws
Java.IO.FileNotFoundExceptionThrows FileNotFoundException if there is no file associated with the given URI or the mode is invalid.
Java.Lang.SecurityExceptionThrows SecurityException if the caller does not have permission to access the file.
See Also

public Android.Content.Res.AssetFileDescriptoropenAssetFile(Android.Net.Uri uri, Java.Lang.String mode)

Added in API level 3

This is like ContentProvider.OpenFile(Android.Net.Uri, System.String), but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .apk. This method can be called from multiple threads, as described in Processes and Threads.

If you implement this, your clients must be able to deal with such file slices, either directly with ContentResolver.OpenAssetFileDescriptor(Android.Net.Uri, System.String), or by using the higher-level ContentResolver.OpenInputStream(Android.Net.Uri) or ContentResolver.OpenOutputStream(Android.Net.Uri) methods.

The returned AssetFileDescriptor can be a pipe or socket pair to enable streaming of data.

If you are implementing this to return a full file, you should create the AssetFileDescriptor with Android.Content.Res.AssetFileDescriptor.UnknownLength to be compatible with applications that cannot handle sub-sections of files.

For use in Intents, you will want to implement ContentProvider.GetType(Android.Net.Uri) to return the appropriate MIME type for the data returned here with the same URI. This will allow intent resolution to automatically determine the data MIME type and select the appropriate matching targets as part of its operation.

For better interoperability with other applications, it is recommended that for any URIs that can be opened, you also support queries on them containing at least the columns specified by Android.Provider.OpenableColumns.

Parameters
uri The URI whose file is to be opened.
mode Access mode for the file. May be "r" for read-only access, "w" for write-only access (erasing whatever data is currently in the file), "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data, and "rwt" for read and write access that truncates any existing file.
Returns
Throws
Java.IO.FileNotFoundExceptionThrows FileNotFoundException if there is no file associated with the given URI or the mode is invalid.
Java.Lang.SecurityExceptionThrows SecurityException if the caller does not have permission to access the file.
See Also

public Android.OS.ParcelFileDescriptoropenFile(Android.Net.Uri uri, Java.Lang.String mode)

Added in API level 1

Override this to handle requests to open a file blob. The default implementation always throws Java.IO.FileNotFoundException. This method can be called from multiple threads, as described in Processes and Threads.

This method returns a ParcelFileDescriptor, which is returned directly to the caller. This way large data (such as images and documents) can be returned without copying the content.

The returned ParcelFileDescriptor is owned by the caller, so it is their responsibility to close it when done. That is, the implementation of this method should create a new ParcelFileDescriptor for each call.

If opened with the exclusive "r" or "w" modes, the returned ParcelFileDescriptor can be a pipe or socket pair to enable streaming of data. Opening with the "rw" or "rwt" modes implies a file on disk that supports seeking.

If you need to detect when the returned ParcelFileDescriptor has been closed, or if the remote process has crashed or encountered some other error, you can use Android.OS.ParcelFileDescriptor.Open(Java.IO.File, Android.OS.ParcelFileMode, Android.OS.ParcelFileMode, Android.OS.ParcelFileMode), Android.OS.ParcelFileDescriptor.CreateReliablePipe, or Android.OS.ParcelFileDescriptor.CreateReliableSocketPair.

For use in Intents, you will want to implement ContentProvider.GetType(Android.Net.Uri) to return the appropriate MIME type for the data returned here with the same URI. This will allow intent resolution to automatically determine the data MIME type and select the appropriate matching targets as part of its operation.

For better interoperability with other applications, it is recommended that for any URIs that can be opened, you also support queries on them containing at least the columns specified by Android.Provider.OpenableColumns. You may also want to support other common columns if you have additional meta-data to supply, such as NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html#DATE_ADDED in NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html.

Parameters
uri The URI whose file is to be opened.
mode Access mode for the file. May be "r" for read-only access, "rw" for read and write access, or "rwt" for read and write access that truncates any existing file.
Returns
Throws
Java.IO.FileNotFoundExceptionThrows FileNotFoundException if there is no file associated with the given URI or the mode is invalid.
Java.Lang.SecurityExceptionThrows SecurityException if the caller does not have permission to access the file.
See Also

public Android.OS.ParcelFileDescriptoropenFile(Android.Net.Uri uri, Java.Lang.String mode, Android.OS.CancellationSignal signal)

Added in API level 19

Override this to handle requests to open a file blob. The default implementation always throws Java.IO.FileNotFoundException. This method can be called from multiple threads, as described in Processes and Threads.

This method returns a ParcelFileDescriptor, which is returned directly to the caller. This way large data (such as images and documents) can be returned without copying the content.

The returned ParcelFileDescriptor is owned by the caller, so it is their responsibility to close it when done. That is, the implementation of this method should create a new ParcelFileDescriptor for each call.

If opened with the exclusive "r" or "w" modes, the returned ParcelFileDescriptor can be a pipe or socket pair to enable streaming of data. Opening with the "rw" or "rwt" modes implies a file on disk that supports seeking.

If you need to detect when the returned ParcelFileDescriptor has been closed, or if the remote process has crashed or encountered some other error, you can use Android.OS.ParcelFileDescriptor.Open(Java.IO.File, Android.OS.ParcelFileMode, Android.OS.ParcelFileMode, Android.OS.ParcelFileMode), Android.OS.ParcelFileDescriptor.CreateReliablePipe, or Android.OS.ParcelFileDescriptor.CreateReliableSocketPair.

For use in Intents, you will want to implement ContentProvider.GetType(Android.Net.Uri) to return the appropriate MIME type for the data returned here with the same URI. This will allow intent resolution to automatically determine the data MIME type and select the appropriate matching targets as part of its operation.

For better interoperability with other applications, it is recommended that for any URIs that can be opened, you also support queries on them containing at least the columns specified by Android.Provider.OpenableColumns. You may also want to support other common columns if you have additional meta-data to supply, such as NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html#DATE_ADDED in NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html.

Parameters
uri The URI whose file is to be opened.
mode Access mode for the file. May be "r" for read-only access, "w" for write-only access, "rw" for read and write access, or "rwt" for read and write access that truncates any existing file.
signal A signal to cancel the operation in progress, or null if none. For example, if you are downloading a file from the network to service a "rw" mode request, you should periodically call Android.OS.CancellationSignal.ThrowIfCanceled to check whether the client has canceled the request and abort the download.
Returns
Throws
Java.IO.FileNotFoundExceptionThrows FileNotFoundException if there is no file associated with the given URI or the mode is invalid.
Java.Lang.SecurityExceptionThrows SecurityException if the caller does not have permission to access the file.
See Also

public Android.OS.ParcelFileDescriptoropenPipeHelper(Android.Net.Uri uri, Java.Lang.String mimeType, Android.OS.Bundle opts, T args, NoType:android/content/ContentProvider$PipeDataWriter;Href=../../../reference/android/content/ContentProvider.PipeDataWriter.html<T> func)

Added in API level 11

A helper function for implementing ContentProvider.OpenTypedAssetFile(Android.Net.Uri, System.String, System.String), for creating a data pipe and background thread allowing you to stream generated data back to the client. This function returns a new ParcelFileDescriptor that should be returned to the caller (the caller is responsible for closing it).

Parameters
uri The URI whose data is to be written.
mimeType The desired type of data to be written.
opts Options supplied by caller.
args Your own custom arguments.
func Interface implementing the function that will actually stream the data.
Returns
Throws
Java.IO.FileNotFoundException

public Android.Content.Res.AssetFileDescriptoropenTypedAssetFile(Android.Net.Uri uri, Java.Lang.String mimeTypeFilter, Android.OS.Bundle opts)

Added in API level 11

Called by a client to open a read-only stream containing data of a particular MIME type. This is like ContentProvider.OpenAssetFile(Android.Net.Uri, System.String), except the file can only be read-only and the content provider may perform data conversions to generate data of the desired type.

The default implementation compares the given mimeType against the result of ContentProvider.GetType(Android.Net.Uri) and, if they match, simply calls ContentProvider.OpenAssetFile(Android.Net.Uri, System.String).

See Android.Content.ClipData for examples of the use and implementation of this method.

The returned AssetFileDescriptor can be a pipe or socket pair to enable streaming of data.

For better interoperability with other applications, it is recommended that for any URIs that can be opened, you also support queries on them containing at least the columns specified by Android.Provider.OpenableColumns. You may also want to support other common columns if you have additional meta-data to supply, such as NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html#DATE_ADDED in NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html.

Parameters
uri The data in the content provider being queried.
mimeTypeFilter The type of data the client desires. May be a pattern, such as *&#47;*, if the caller does not have specific type requirements; in this case the content provider will pick its best type matching the pattern.
opts Additional options from the client. The definitions of these are specific to the content provider being called.
Returns
Throws
Java.IO.FileNotFoundExceptionThrows FileNotFoundException if there is no file associated with the given URI or the mode is invalid.
Java.Lang.SecurityExceptionThrows SecurityException if the caller does not have permission to access the data.
Java.Lang.IllegalArgumentExceptionThrows IllegalArgumentException if the content provider does not support the requested MIME type.
See Also

public Android.Content.Res.AssetFileDescriptoropenTypedAssetFile(Android.Net.Uri uri, Java.Lang.String mimeTypeFilter, Android.OS.Bundle opts, Android.OS.CancellationSignal signal)

Added in API level 19

Called by a client to open a read-only stream containing data of a particular MIME type. This is like ContentProvider.OpenAssetFile(Android.Net.Uri, System.String), except the file can only be read-only and the content provider may perform data conversions to generate data of the desired type.

The default implementation compares the given mimeType against the result of ContentProvider.GetType(Android.Net.Uri) and, if they match, simply calls ContentProvider.OpenAssetFile(Android.Net.Uri, System.String).

See Android.Content.ClipData for examples of the use and implementation of this method.

The returned AssetFileDescriptor can be a pipe or socket pair to enable streaming of data.

For better interoperability with other applications, it is recommended that for any URIs that can be opened, you also support queries on them containing at least the columns specified by Android.Provider.OpenableColumns. You may also want to support other common columns if you have additional meta-data to supply, such as NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html#DATE_ADDED in NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html.

Parameters
uri The data in the content provider being queried.
mimeTypeFilter The type of data the client desires. May be a pattern, such as *&#47;*, if the caller does not have specific type requirements; in this case the content provider will pick its best type matching the pattern.
opts Additional options from the client. The definitions of these are specific to the content provider being called.
signal A signal to cancel the operation in progress, or null if none. For example, if you are downloading a file from the network to service a "rw" mode request, you should periodically call Android.OS.CancellationSignal.ThrowIfCanceled to check whether the client has canceled the request and abort the download.
Returns
Throws
Java.IO.FileNotFoundExceptionThrows FileNotFoundException if there is no file associated with the given URI or the mode is invalid.
Java.Lang.SecurityExceptionThrows SecurityException if the caller does not have permission to access the data.
Java.Lang.IllegalArgumentExceptionThrows IllegalArgumentException if the content provider does not support the requested MIME type.
See Also

public abstract Android.Database.ICursorquery(Android.Net.Uri uri, Java.Lang.String projection, Java.Lang.String selection, Java.Lang.String selectionArgs, Java.Lang.String sortOrder)

Added in API level 1

Implement this to handle query requests from clients. This method can be called from multiple threads, as described in Processes and Threads.

Example client call:

java Example

// Request a specific record.
 Cursor managedCursor = managedQuery(
                ContentUris.withAppendedId(Contacts.People.CONTENT_URI, 2),
                projection,    // Which columns to return.
                null,          // WHERE clause.
                null,          // WHERE clause value substitution
                People.NAME + " ASC");   // Sort order.
Example implementation:

java Example

// SQLiteQueryBuilder is a helper class that creates the
        // proper SQL syntax for us.
        SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();

        // Set the table we're querying.
        qBuilder.setTables(DATABASE_TABLE_NAME);

        // If the query ends in a specific record number, we're
        // being asked for a specific record, so set the
        // WHERE clause in our query.
        if((URI_MATCHER.match(uri)) == SPECIFIC_MESSAGE){
            qBuilder.appendWhere("_id=" + uri.getPathLeafId());
        }

        // Make the query.
        Cursor c = qBuilder.query(mDb,
                projection,
                selection,
                selectionArgs,
                groupBy,
                having,
                sortOrder);
        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;

Parameters
uri The URI to query. This will be the full URI sent by the client; if the client is requesting a specific record, the URI will end in a record number that the implementation should parse and add to a WHERE or HAVING clause, specifying that _id value.
projection The list of columns to put into the cursor. If null all columns are included.
selection A selection criteria to apply when filtering rows. If null then all rows are included.
selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
sortOrder How the rows in the cursor should be sorted. If null then the provider is free to define the sort order.
Returns

public Android.Database.ICursorquery(Android.Net.Uri uri, Java.Lang.String projection, Java.Lang.String selection, Java.Lang.String selectionArgs, Java.Lang.String sortOrder, Android.OS.CancellationSignal cancellationSignal)

Added in API level 16

Implement this to handle query requests from clients with support for cancellation. This method can be called from multiple threads, as described in Processes and Threads.

Example client call:

java Example

// Request a specific record.
 Cursor managedCursor = managedQuery(
                ContentUris.withAppendedId(Contacts.People.CONTENT_URI, 2),
                projection,    // Which columns to return.
                null,          // WHERE clause.
                null,          // WHERE clause value substitution
                People.NAME + " ASC");   // Sort order.
Example implementation:

java Example

// SQLiteQueryBuilder is a helper class that creates the
        // proper SQL syntax for us.
        SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();

        // Set the table we're querying.
        qBuilder.setTables(DATABASE_TABLE_NAME);

        // If the query ends in a specific record number, we're
        // being asked for a specific record, so set the
        // WHERE clause in our query.
        if((URI_MATCHER.match(uri)) == SPECIFIC_MESSAGE){
            qBuilder.appendWhere("_id=" + uri.getPathLeafId());
        }

        // Make the query.
        Cursor c = qBuilder.query(mDb,
                projection,
                selection,
                selectionArgs,
                groupBy,
                having,
                sortOrder);
        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;

If you implement this method then you must also implement the version of ContentProvider.Query(Android.Net.Uri, System.String[], System.String[], System.String[], System.String[]) that does not take a cancellation signal to ensure correct operation on older versions of the Android Framework in which the cancellation signal overload was not available.

Parameters
uri The URI to query. This will be the full URI sent by the client; if the client is requesting a specific record, the URI will end in a record number that the implementation should parse and add to a WHERE or HAVING clause, specifying that _id value.
projection The list of columns to put into the cursor. If null all columns are included.
selection A selection criteria to apply when filtering rows. If null then all rows are included.
selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
sortOrder How the rows in the cursor should be sorted. If null then the provider is free to define the sort order.
cancellationSignal A signal to cancel the operation in progress, or null if none. If the operation is canceled, then Android.OS.OperationCanceledException will be thrown when the query is executed.
Returns

public void shutdown()

Added in API level 11

Implement this to shut down the ContentProvider instance. You can then invoke this method in unit tests.

Android normally handles ContentProvider startup and shutdown automatically. You do not need to start up or shut down a ContentProvider. When you invoke a test method on a ContentProvider, however, a ContentProvider instance is started and keeps running after the test finishes, even if a succeeding test instantiates another ContentProvider. A conflict develops because the two instances are usually running against the same underlying data source (for example, an sqlite database).

Implementing shutDown() avoids this conflict by providing a way to terminate the ContentProvider. This method can also prevent memory leaks from multiple instantiations of the ContentProvider, and it can ensure unit test isolation by allowing you to completely clean up the test fixture before moving on to the next test.

public Android.Net.Uriuncanonicalize(Android.Net.Uri url)

Added in API level 19

Remove canonicalization from canonical URIs previously returned by ContentProvider.Canonicalize(Android.Net.Uri). For example, if your implementation is to add a query param to canonicalize a URI, this method can simply trip any query params on the URI. The default implementation always returns the same url that was passed in.

Parameters
url The Uri to remove any canonicalization from.
Returns

public abstract int update(Android.Net.Uri uri, Android.Content.ContentValues values, Java.Lang.String selection, Java.Lang.String selectionArgs)

Added in API level 1

Implement this to handle requests to update one or more rows. The implementation should update all rows matching the selection to set the columns according to the provided values map. As a courtesy, call ContentResolver.NotifyChange(Android.Net.Uri, Android.Database.ContentObserver) after updating. This method can be called from multiple threads, as described in Processes and Threads.

Parameters
uri The URI to query. This can potentially have a record ID if this is an update request for a specific record.
values A set of column_name/value pairs to update in the database. This must not be null.
selection An optional filter to match rows to update.
Returns

Protected Methods

protected boolean isTemporary()

Added in API level 1

Returns true if this instance is a temporary content provider.

Returns

protected final Android.OS.ParcelFileDescriptoropenFileHelper(Android.Net.Uri uri, Java.Lang.String mode)

Added in API level 1

Convenience for subclasses that wish to implement ContentProvider.OpenFile(Android.Net.Uri, System.String) by looking up a column named "_data" at the given URI.

Parameters
uri The URI to be opened.
mode The file mode. May be "r" for read-only access, "w" for write-only access (erasing whatever data is currently in the file), "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data, and "rwt" for read and write access that truncates any existing file.
Returns
Throws
Java.IO.FileNotFoundException

protected final void setPathPermissions(Android.Content.PM.PathPermission permissions)

Added in API level 4

Change the path-based permission required to read and/or write data in the content provider. This is normally set for you from its manifest information when the provider is first created.

Parameters
permissions Array of path permission descriptions.

protected final void setReadPermission(Java.Lang.String permission)

Added in API level 1

Change the permission required to read data from the content provider. This is normally set for you from its manifest information when the provider is first created.

Parameters
permission Name of the permission required for read-only access.

protected final void setWritePermission(Java.Lang.String permission)

Added in API level 1

Change the permission required to read and write data in the content provider. This is normally set for you from its manifest information when the provider is first created.

Parameters
permission Name of the permission required for read/write access.
Except as noted, this content is licensed under . For details and restrictions, see the Content License. Android 4.4 r1 &mdash;

About Android  |  Legal  |  Support

[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