Skip to content

Most visited

Recently visited

navigation

MockContentResolver

public class MockContentResolver
extends ContentResolver

java.lang.Object
   ↳ android.content.ContentResolver
     ↳ android.test.mock.MockContentResolver


An extension of 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 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.

Developer Guides

For more information about application testing, read the Testing developer guide.

Summary

Inherited constants

From class android.content.ContentResolver

Public constructors

MockContentResolver()

Creates a local map of providers.

MockContentResolver(Context context)

Creates a local map of providers.

Public methods

void addProvider(String name, ContentProvider provider)

Adds access to a provider based on its authority

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

Overrides ContentResolver.notifChange(Uri, ContentObserver, boolean).

Inherited methods

From class android.content.ContentResolver
From class java.lang.Object

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.

Parameters
context Context

Public methods

addProvider

Added in API level 1
void addProvider (String name, 
                ContentProvider provider)

Adds access to a provider based on its authority

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

notifyChange

Added in API level 1
void notifyChange (Uri uri, 
                ContentObserver observer, 
                boolean syncToNetwork)

Overrides ContentResolver.notifChange(Uri, ContentObserver, boolean). All parameters are ignored. The method hides providers linked to MockContentResolver from other observers in the system.

Parameters
uri Uri: (Ignored) The uri of the content provider.
observer ContentObserver: (Ignored) The observer that originated the change.
syncToNetwork boolean: (Ignored) If true, attempt to sync the change to the network.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.