public class ContentProviderClient extends Object implements AutoCloseable
ContentProvider
.
Instances can be obtained by calling
ContentResolver.acquireContentProviderClient(android.net.Uri)
or
ContentResolver.acquireUnstableContentProviderClient(android.net.Uri)
. Instances must
be released using close()
in order to indicate to the system that
the underlying ContentProvider
is no longer needed and can be killed
to free up resources.
Note that you should generally create a new ContentProviderClient instance
for each thread that will be performing operations. Unlike
ContentResolver
, the methods here such as query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)
and
openFile(android.net.Uri, java.lang.String)
are not thread safe -- you must not call close()
on the ContentProviderClient those calls are made from until you are finished
with the data they have returned.
Constructor and Description |
---|
ContentProviderClient(ContentResolver contentResolver,
IContentProvider contentProvider,
boolean stable) |
Modifier and Type | Method and Description |
---|---|
ContentProviderResult[] |
applyBatch(ArrayList<ContentProviderOperation> operations)
|
int |
bulkInsert(Uri url,
ContentValues[] initialValues)
|
Bundle |
call(String method,
String arg,
Bundle extras)
|
Uri |
canonicalize(Uri url)
|
void |
close()
Closes this client connection, indicating to the system that the
underlying
ContentProvider is no longer needed. |
int |
delete(Uri url,
String selection,
String[] selectionArgs)
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
ContentProvider |
getLocalContentProvider()
Get a reference to the
ContentProvider that is associated with this
client. |
String[] |
getStreamTypes(Uri url,
String mimeTypeFilter)
|
String |
getType(Uri url)
|
Uri |
insert(Uri url,
ContentValues initialValues)
|
AssetFileDescriptor |
openAssetFile(Uri url,
String mode)
|
AssetFileDescriptor |
openAssetFile(Uri url,
String mode,
CancellationSignal signal)
|
ParcelFileDescriptor |
openFile(Uri url,
String mode)
|
ParcelFileDescriptor |
openFile(Uri url,
String mode,
CancellationSignal signal)
|
AssetFileDescriptor |
openTypedAssetFileDescriptor(Uri uri,
String mimeType,
Bundle opts)
|
AssetFileDescriptor |
openTypedAssetFileDescriptor(Uri uri,
String mimeType,
Bundle opts,
CancellationSignal signal)
|
Cursor |
query(Uri url,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder)
|
Cursor |
query(Uri url,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder,
CancellationSignal cancellationSignal)
|
boolean |
release()
Deprecated.
replaced by
close() . |
static void |
releaseQuietly(ContentProviderClient client) |
void |
setDetectNotResponding(long timeoutMillis) |
Uri |
uncanonicalize(Uri url)
|
int |
update(Uri url,
ContentValues values,
String selection,
String[] selectionArgs)
|
public ContentProviderClient(ContentResolver contentResolver, IContentProvider contentProvider, boolean stable)
public void setDetectNotResponding(long timeoutMillis)
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder) throws RemoteException
RemoteException
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) throws RemoteException
RemoteException
public String getType(Uri url) throws RemoteException
RemoteException
public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException
RemoteException
public final Uri canonicalize(Uri url) throws RemoteException
RemoteException
public final Uri uncanonicalize(Uri url) throws RemoteException
RemoteException
public Uri insert(Uri url, ContentValues initialValues) throws RemoteException
RemoteException
public int bulkInsert(Uri url, ContentValues[] initialValues) throws RemoteException
RemoteException
public int delete(Uri url, String selection, String[] selectionArgs) throws RemoteException
RemoteException
public int update(Uri url, ContentValues values, String selection, String[] selectionArgs) throws RemoteException
RemoteException
public ParcelFileDescriptor openFile(Uri url, String mode) throws RemoteException, FileNotFoundException
ContentProvider.openFile
. Note that
this does not
take care of non-content: URIs such as file:. It is strongly recommended
you use the ContentResolver.openFileDescriptor
API instead.RemoteException
FileNotFoundException
public ParcelFileDescriptor openFile(Uri url, String mode, CancellationSignal signal) throws RemoteException, FileNotFoundException
ContentProvider.openFile
. Note that
this does not
take care of non-content: URIs such as file:. It is strongly recommended
you use the ContentResolver.openFileDescriptor
API instead.RemoteException
FileNotFoundException
public AssetFileDescriptor openAssetFile(Uri url, String mode) throws RemoteException, FileNotFoundException
ContentProvider.openAssetFile
.
Note that this does not
take care of non-content: URIs such as file:. It is strongly recommended
you use the ContentResolver.openAssetFileDescriptor
API instead.RemoteException
FileNotFoundException
public AssetFileDescriptor openAssetFile(Uri url, String mode, CancellationSignal signal) throws RemoteException, FileNotFoundException
ContentProvider.openAssetFile
.
Note that this does not
take care of non-content: URIs such as file:. It is strongly recommended
you use the ContentResolver.openAssetFileDescriptor
API instead.RemoteException
FileNotFoundException
public final AssetFileDescriptor openTypedAssetFileDescriptor(Uri uri, String mimeType, Bundle opts) throws RemoteException, FileNotFoundException
RemoteException
FileNotFoundException
public final AssetFileDescriptor openTypedAssetFileDescriptor(Uri uri, String mimeType, Bundle opts, CancellationSignal signal) throws RemoteException, FileNotFoundException
RemoteException
FileNotFoundException
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws RemoteException, OperationApplicationException
public Bundle call(String method, String arg, Bundle extras) throws RemoteException
RemoteException
public void close()
ContentProvider
is no longer needed.close
in interface AutoCloseable
@Deprecated public boolean release()
close()
.protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
public ContentProvider getLocalContentProvider()
ContentProvider
that is associated with this
client. If the ContentProvider
is running in a different process then
null will be returned. This can be used if you know you are running in the same
process as a provider, and want to get direct access to its implementation details.ContentProvider
is local, returns it.
Otherwise returns null.public static void releaseQuietly(ContentProviderClient client)