ContentProvider Class

Definition

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

[Android.Runtime.Register("android/content/ContentProvider", DoNotGenerateAcw=true)]
public abstract class ContentProvider : Java.Lang.Object, Android.Content.IComponentCallbacks2, IDisposable
[<Android.Runtime.Register("android/content/ContentProvider", DoNotGenerateAcw=true)>]
type ContentProvider = class
    inherit Object
    interface IComponentCallbacks
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IComponentCallbacks2
Inheritance
ContentProvider
Derived
Attributes
Implements

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 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 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 UriMatcher class is helpful for parsing URIs.

The primary methods that need to be implemented are: <ul> <li>#onCreate which is called to initialize the provider</li> <li>#query which returns data to the caller</li> <li>#insert which inserts new data into the content provider</li> <li>#update which updates existing data in the content provider</li> <li>#delete which deletes data from the content provider</li> <li>#getType which returns the MIME type of data in the content provider</li> </ul>

Data access methods (such as #insert and #update) may be called from many threads at once, and must be thread-safe. Other methods (such as #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 ContentResolver are automatically forwarded to the appropriate ContentProvider instance, so subclasses don't have to worry about the details of cross-process calls.

<div class="special reference"> <h3>Developer Guides</h3>

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

</div>

Java documentation for android.content.ContentProvider.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Name Description
ContentProvider()

Construct a ContentProvider instance.

ContentProvider(IntPtr, JniHandleOwnership)

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

Properties

Name Description
CallingAttributionSource

Gets the attribution source of the calling app.

CallingAttributionTag

Return the attribution tag of the caller that initiated the request being processed on the current thread.

CallingPackage

Return the package name of the caller that initiated the request being processed on the current thread.

CallingPackageUnchecked

Return the package name of the caller that initiated the request being processed on the current thread.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Context

Retrieves the Context this provider is running in.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsTemporary

Returns true if this instance is a temporary content provider.

JniIdentityHashCode

Gets the identity hash code assigned to this Java peer by the interop runtime.

(Inherited from Object)
JniManagedPeerState (Inherited from JavaObject)
JniPeerMembers

Gets the JNI metadata used to invoke members of this Java peer.

PeerReference

Gets the JNI object reference for this Java peer.

(Inherited from Object)
ReadPermission
Obsolete.

Return the name of the permission required for read-only access to this content provider. -or- Change the permission required to read data from the content provider.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

WritePermission
Obsolete.

Return the name of the permission required for read/write access to this content provider. -or- Change the permission required to read and write data in the content provider.

Methods

Name Description
ApplyBatch(IList<ContentProviderOperation>)

Override this to handle requests to perform a batch of operations, or the default implementation will iterate over the operations and call ContentProviderOperation#apply on each of them.

ApplyBatch(String, IList<ContentProviderOperation>)

Override this to handle requests to perform a batch of operations, or the default implementation will iterate over the operations and call ContentProviderOperation#apply on each of them.

AttachInfo(Context, ProviderInfo)

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

BulkInsert(Uri, ContentValues[])

Override this to handle requests to insert a set of new rows, or the default implementation will iterate over the values and call #insert on each of them.

Call(String, String, Bundle)

Call a provider-defined method.

Call(String, String, String, Bundle)

Call a provider-defined method.

Canonicalize(Uri)

Implement this to support canonicalization of URIs that refer to your content provider.

ClearCallingIdentity()

Reset the identity of the incoming IPC on the current thread.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Construct(JniObjectReference, JniObjectReferenceOptions) (Inherited from JavaObject)
Delete(Uri, Bundle)

Implement this to handle requests to delete one or more rows.

Delete(Uri, String, String[])

Implement this to handle requests to delete one or more rows.

Dispose()

Releases the resources held by this Java peer.

(Inherited from Object)
Dispose(Boolean)

Releases the resources held by this Java peer.

(Inherited from Object)
DisposeUnlessReferenced() (Inherited from JavaObject)
Dump(FileDescriptor, PrintWriter, String[])

Print the Provider's state into the given stream.

DumpAsync(FileDescriptor, PrintWriter, String[])

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

Equals(Object) (Inherited from JavaObject)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetPathPermissions()

Return the path-based permissions required for read and/or write access to this content provider.

GetStreamTypes(Uri, String)

Called by a client to determine the types of data streams that this content provider supports for the given URI.

GetType(Uri)

Implement this to handle requests for the MIME type of the data at the given URI.

GetTypeAnonymous(Uri)

Implement this to handle requests for MIME type of URIs, that does not need to reveal any internal information which should be protected by any permission.

Insert(Uri, ContentValues, Bundle)

Implement this to handle requests to insert a new row.

Insert(Uri, ContentValues)

Implement this to handle requests to insert a new row.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
OnCallingPackageChanged()

Called whenever the value of #getCallingPackage() changes, giving the provider an opportunity to invalidate any security related caching it may be performing.

OnConfigurationChanged(Configuration)

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 Configuration : The new device configuration. This value cannot be null .

OnCreate()

Implement this to initialize your content provider on startup.

OnLowMemory()

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

OnTrimMemory(TrimMemory)

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.

OpenAssetFile(Uri, String, CancellationSignal)

This is like #openFile, but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .

OpenAssetFile(Uri, String)

This is like #openFile, but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .

OpenFile(Uri, String, CancellationSignal)

Override this to handle requests to open a file blob.

OpenFile(Uri, String)

Override this to handle requests to open a file blob.

OpenFileHelper(Uri, String)

Convenience for subclasses that wish to implement #openFile by looking up a column named "_data" at the given URI.

OpenPipeHelper(Uri, String, Bundle, Object, ContentProvider+IPipeDataWriter)

A helper function for implementing #openTypedAssetFile, for creating a data pipe and background thread allowing you to stream generated data back to the client.

OpenTypedAssetFile(Uri, String, Bundle, CancellationSignal)

Called by a client to open a read-only stream containing data of a particular MIME type.

OpenTypedAssetFile(Uri, String, Bundle)

Called by a client to open a read-only stream containing data of a particular MIME type.

Query(Uri, String[], Bundle, CancellationSignal)

Implement this to handle query requests where the arguments are packed into a Bundle.

Query(Uri, String[], String, String[], String, CancellationSignal)

Implement this to handle query requests from clients with support for cancellation.

Query(Uri, String[], String, String[], String)

Implement this to handle query requests from clients.

Refresh(Uri, Bundle, CancellationSignal)

Implement this to support refresh of content identified by uri.

RequireContext()

Retrieves a Non-Nullable Context this provider is running in, this is intended to be called after #onCreate.

RestoreCallingIdentity(ContentProvider+CallingIdentity)

Restore the identity of the incoming IPC on the current thread back to a previously identity that was returned by #clearCallingIdentity.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetPathPermissions(PathPermission[])

Change the path-based permission required to read and/or write data in the content provider.

SetPeerReference(JniObjectReference, JniObjectReferenceOptions) (Inherited from JavaObject)
SetReadPermission(String)

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.

SetWritePermission(String)

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

Shutdown()

Implement this to shut down the ContentProvider instance.

ToArray<T>()

Creates a managed array from this Java array wrapper.

(Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
Uncanonicalize(Uri)

Remove canonicalization from canonical URIs previously returned by #canonicalize.

UnregisterFromRuntime()

Unregisters this Java peer from the interop runtime.

(Inherited from Object)
Update(Uri, ContentValues, Bundle)

Implement this to handle requests to update one or more rows.

Update(Uri, ContentValues, String, String[])

Implement this to handle requests to update one or more rows.

Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

Name Description
IJavaPeerable.Disposed() (Inherited from JavaObject)
IJavaPeerable.Finalized() (Inherited from JavaObject)
IJavaPeerable.JniObjectReferenceControlBlock (Inherited from JavaObject)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from JavaObject)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from JavaObject)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from JavaObject)
IJavaPeerable.UnregisterFromRuntime()

Extension Methods

Name Description
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to