Added in API level 1

MockContentResolver


open class MockContentResolver : ContentResolver
kotlin.Any
   ↳ android.content.ContentResolver
   ↳ android.test.mock.MockContentResolver

An extension of android.content.ContentResolver that is designed for testing.

MockContentResolver overrides Android's normal way of resolving providers by authority. To have access to a provider based on its authority, users of MockContentResolver first instantiate the provider and use MockContentResolver#addProvider(String, ContentProvider). Resolution of an authority occurs entirely within MockContentResolver.

Users can also set an authority's entry in the map to null, so that a provider is completely mocked out.

Summary

Inherited constants
Public constructors

Creates a local map of providers.

Creates a local map of providers.

Public methods
open Unit
addProvider(name: String!, provider: ContentProvider!)

Adds access to a provider based on its authority

open Unit
notifyChange(uri: Uri, observer: ContentObserver?)

Overrides the behavior from the parent class to completely ignore any content notifications sent to this object.

open Unit
notifyChange(uri: Uri, observer: ContentObserver?, syncToNetwork: Boolean)

Overrides the behavior from the parent class to completely ignore any content notifications sent to this object.

open Unit
notifyChange(uri: Uri, observer: ContentObserver?, flags: Int)

Overrides the behavior from the parent class to completely ignore any content notifications sent to this object.

open Unit
notifyChange(uris: MutableCollection<Uri!>, observer: ContentObserver?, flags: Int)

Overrides the behavior from the parent class to completely ignore any content notifications sent to this object.

Inherited functions

Public constructors

MockContentResolver

Added in API level 1
MockContentResolver()

Creates a local map of providers. This map is used instead of the global map when an API call tries to acquire a provider.

MockContentResolver

Added in API level 18
MockContentResolver(context: Context!)

Creates a local map of providers. This map is used instead of the global map when an API call tries to acquire a provider.

Public methods

addProvider

Added in API level 1
open fun addProvider(
    name: String!,
    provider: ContentProvider!
): Unit

Adds access to a provider based on its authority

Parameters
name String!: The authority name associated with the provider.
provider ContentProvider!: An instance of android.content.ContentProvider or one of its subclasses, or null.

notifyChange

Added in API level 1
open fun notifyChange(
    uri: Uri,
    observer: ContentObserver?
): Unit

Overrides the behavior from the parent class to completely ignore any content notifications sent to this object. This effectively hides clients from observers elsewhere in the system.

Parameters
uri Uri: This value cannot be null.
observer ContentObserver?: This value may be null.

notifyChange

Added in API level 1
open fun notifyChange(
    uri: Uri,
    observer: ContentObserver?,
    syncToNetwork: Boolean
): Unit

Deprecated: callers should consider migrating to notifyChange(android.net.Uri,android.database.ContentObserver,int), as it offers support for many more options than just NOTIFY_SYNC_TO_NETWORK.

Overrides the behavior from the parent class to completely ignore any content notifications sent to this object. This effectively hides clients from observers elsewhere in the system.

Parameters
uri Uri: This value cannot be null.
observer ContentObserver?: This value may be null.
syncToNetwork Boolean: If true, same as NOTIFY_SYNC_TO_NETWORK.

notifyChange

Added in API level 24
open fun notifyChange(
    uri: Uri,
    observer: ContentObserver?,
    flags: Int
): Unit

Overrides the behavior from the parent class to completely ignore any content notifications sent to this object. This effectively hides clients from observers elsewhere in the system.

Parameters
uri Uri: This value cannot be null.
observer ContentObserver?: This value may be null.
flags Int: Value is either 0 or a combination of android.content.ContentResolver#NOTIFY_SYNC_TO_NETWORK, android.content.ContentResolver#NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS, android.content.ContentResolver#NOTIFY_INSERT, android.content.ContentResolver#NOTIFY_UPDATE, and android.content.ContentResolver#NOTIFY_DELETE

notifyChange

Added in API level 30
open fun notifyChange(
    uris: MutableCollection<Uri!>,
    observer: ContentObserver?,
    flags: Int
): Unit

Overrides the behavior from the parent class to completely ignore any content notifications sent to this object. This effectively hides clients from observers elsewhere in the system.

Parameters
uris MutableCollection<Uri!>: This value cannot be null.
observer ContentObserver?: This value may be null.
flags Int: Value is either 0 or a combination of android.content.ContentResolver#NOTIFY_SYNC_TO_NETWORK, android.content.ContentResolver#NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS, android.content.ContentResolver#NOTIFY_INSERT, android.content.ContentResolver#NOTIFY_UPDATE, and android.content.ContentResolver#NOTIFY_DELETE