Methods Summary |
---|
public final IContentProvider | acquireProvider(android.net.Uri uri)Returns the content provider for the given content URI..
if (!SCHEME_CONTENT.equals(uri.getScheme())) {
return null;
}
String auth = uri.getAuthority();
if (auth != null) {
return acquireProvider(mContext, uri.getAuthority());
}
return null;
|
public final IContentProvider | acquireProvider(java.lang.String name)
if(name == null) {
return null;
}
return acquireProvider(mContext, name);
|
protected abstract IContentProvider | acquireProvider(Context c, java.lang.String name)
|
public final int | bulkInsert(android.net.Uri url, ContentValues[] values)Inserts multiple rows into a table at the given URL.
This function make no guarantees about the atomicity of the insertions.
IContentProvider provider = acquireProvider(url);
if (provider == null) {
throw new IllegalArgumentException("Unknown URL " + url);
}
try {
return provider.bulkInsert(url, values);
} catch (RemoteException e) {
return 0;
} finally {
releaseProvider(provider);
}
|
public void | cancelSync(android.net.Uri uri)
try {
ContentServiceNative.getDefault().cancelSync(uri);
} catch (RemoteException e) {
}
|
public final int | delete(android.net.Uri url, java.lang.String where, java.lang.String[] selectionArgs)Deletes row(s) specified by a content URI.
If the content provider supports transactions, the deletion will be atomic.
IContentProvider provider = acquireProvider(url);
if (provider == null) {
throw new IllegalArgumentException("Unknown URL " + url);
}
try {
return provider.delete(url, where, selectionArgs);
} catch (RemoteException e) {
return -1;
} finally {
releaseProvider(provider);
}
|
android.content.ContentResolver$OpenResourceIdResult | getResourceId(android.net.Uri uri)
String authority = uri.getAuthority();
Resources r;
if (TextUtils.isEmpty(authority)) {
throw new FileNotFoundException("No authority: " + uri);
} else {
try {
r = mContext.getPackageManager().getResourcesForApplication(authority);
} catch (NameNotFoundException ex) {
throw new FileNotFoundException("No package found for authority: " + uri);
}
}
List<String> path = uri.getPathSegments();
if (path == null) {
throw new FileNotFoundException("No path: " + uri);
}
int len = path.size();
int id;
if (len == 1) {
try {
id = Integer.parseInt(path.get(0));
} catch (NumberFormatException e) {
throw new FileNotFoundException("Single path segment is not a resource ID: " + uri);
}
} else if (len == 2) {
id = r.getIdentifier(path.get(1), path.get(0), authority);
} else {
throw new FileNotFoundException("More than two path segments: " + uri);
}
if (id == 0) {
throw new FileNotFoundException("No resource found for: " + uri);
}
OpenResourceIdResult res = new OpenResourceIdResult();
res.r = r;
res.id = id;
return res;
|
public final java.lang.String | getType(android.net.Uri url)Return the MIME type of the given content URL.
IContentProvider provider = acquireProvider(url);
if (provider == null) {
return null;
}
try {
return provider.getType(url);
} catch (RemoteException e) {
return null;
} catch (java.lang.Exception e) {
return null;
} finally {
releaseProvider(provider);
}
|
public final android.net.Uri | insert(android.net.Uri url, ContentValues values)Inserts a row into a table at the given URL.
If the content provider supports transactions the insertion will be atomic.
IContentProvider provider = acquireProvider(url);
if (provider == null) {
throw new IllegalArgumentException("Unknown URL " + url);
}
try {
return provider.insert(url, values);
} catch (RemoteException e) {
return null;
} finally {
releaseProvider(provider);
}
|
public static int | modeToMode(android.net.Uri uri, java.lang.String mode)
int modeBits;
if ("r".equals(mode)) {
modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
} else if ("w".equals(mode) || "wt".equals(mode)) {
modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
| ParcelFileDescriptor.MODE_CREATE
| ParcelFileDescriptor.MODE_TRUNCATE;
} else if ("wa".equals(mode)) {
modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
| ParcelFileDescriptor.MODE_CREATE
| ParcelFileDescriptor.MODE_APPEND;
} else if ("rw".equals(mode)) {
modeBits = ParcelFileDescriptor.MODE_READ_WRITE
| ParcelFileDescriptor.MODE_CREATE;
} else if ("rwt".equals(mode)) {
modeBits = ParcelFileDescriptor.MODE_READ_WRITE
| ParcelFileDescriptor.MODE_CREATE
| ParcelFileDescriptor.MODE_TRUNCATE;
} else {
throw new FileNotFoundException("Bad mode for " + uri + ": "
+ mode);
}
return modeBits;
|
public void | notifyChange(android.net.Uri uri, android.database.ContentObserver observer)Notify registered observers that a row was updated.
To register, call {@link #registerContentObserver(android.net.Uri , boolean, android.database.ContentObserver) registerContentObserver()}.
By default, CursorAdapter objects will get this notification.
notifyChange(uri, observer, true /* sync to network */);
|
public void | notifyChange(android.net.Uri uri, android.database.ContentObserver observer, boolean syncToNetwork)Notify registered observers that a row was updated.
To register, call {@link #registerContentObserver(android.net.Uri , boolean, android.database.ContentObserver) registerContentObserver()}.
By default, CursorAdapter objects will get this notification.
try {
ContentServiceNative.getDefault().notifyChange(
uri, observer == null ? null : observer.getContentObserver(),
observer != null && observer.deliverSelfNotifications(), syncToNetwork);
} catch (RemoteException e) {
}
|
public final android.content.res.AssetFileDescriptor | openAssetFileDescriptor(android.net.Uri uri, java.lang.String mode)Open a raw file descriptor to access data under a "content:" URI. This
interacts with the underlying {@link ContentProvider#openAssetFile}
ContentProvider.openAssetFile()} method of the provider associated with the
given URI, to retrieve any file stored there.
Accepts the following URI schemes:
- content ({@link #SCHEME_CONTENT})
- android.resource ({@link #SCHEME_ANDROID_RESOURCE})
- file ({@link #SCHEME_FILE})
The android.resource ({@link #SCHEME_ANDROID_RESOURCE}) Scheme
A Uri object can be used to reference a resource in an APK file. The
Uri should be one of the following formats:
String scheme = uri.getScheme();
if (SCHEME_ANDROID_RESOURCE.equals(scheme)) {
if (!"r".equals(mode)) {
throw new FileNotFoundException("Can't write resources: " + uri);
}
OpenResourceIdResult r = getResourceId(uri);
try {
return r.r.openRawResourceFd(r.id);
} catch (Resources.NotFoundException ex) {
throw new FileNotFoundException("Resource does not exist: " + uri);
}
} else if (SCHEME_FILE.equals(scheme)) {
ParcelFileDescriptor pfd = ParcelFileDescriptor.open(
new File(uri.getPath()), modeToMode(uri, mode));
return new AssetFileDescriptor(pfd, 0, -1);
} else {
IContentProvider provider = acquireProvider(uri);
if (provider == null) {
throw new FileNotFoundException("No content provider: " + uri);
}
try {
AssetFileDescriptor fd = provider.openAssetFile(uri, mode);
if(fd == null) {
releaseProvider(provider);
return null;
}
ParcelFileDescriptor pfd = new ParcelFileDescriptorInner(
fd.getParcelFileDescriptor(), provider);
return new AssetFileDescriptor(pfd, fd.getStartOffset(),
fd.getDeclaredLength());
} catch (RemoteException e) {
releaseProvider(provider);
throw new FileNotFoundException("Dead content provider: " + uri);
} catch (FileNotFoundException e) {
releaseProvider(provider);
throw e;
} catch (RuntimeException e) {
releaseProvider(provider);
throw e;
}
}
|
public final android.os.ParcelFileDescriptor | openFileDescriptor(android.net.Uri uri, java.lang.String mode)Open a raw file descriptor to access data under a "content:" URI. This
is like {@link #openAssetFileDescriptor(Uri, String)}, but uses the
underlying {@link ContentProvider#openFile}
ContentProvider.openFile()} method, so will not work with
providers that return sub-sections of files. If at all possible,
you should use {@link #openAssetFileDescriptor(Uri, String)}. You
will receive a FileNotFoundException exception if the provider returns a
sub-section of a file.
Accepts the following URI schemes:
- content ({@link #SCHEME_CONTENT})
- file ({@link #SCHEME_FILE})
See {@link #openAssetFileDescriptor(Uri, String)} for more information
on these schemes.
AssetFileDescriptor afd = openAssetFileDescriptor(uri, mode);
if (afd == null) {
return null;
}
if (afd.getDeclaredLength() < 0) {
// This is a full file!
return afd.getParcelFileDescriptor();
}
// Client can't handle a sub-section of a file, so close what
// we got and bail with an exception.
try {
afd.close();
} catch (IOException e) {
}
throw new FileNotFoundException("Not a whole file");
|
public final java.io.InputStream | openInputStream(android.net.Uri uri)Open a stream on to the content associated with a content URI. If there
is no data associated with the URI, FileNotFoundException is thrown.
Accepts the following URI schemes:
- content ({@link #SCHEME_CONTENT})
- android.resource ({@link #SCHEME_ANDROID_RESOURCE})
- file ({@link #SCHEME_FILE})
See {@link #openAssetFileDescriptor(Uri, String)} for more information
on these schemes.
String scheme = uri.getScheme();
if (SCHEME_ANDROID_RESOURCE.equals(scheme)) {
// Note: left here to avoid breaking compatibility. May be removed
// with sufficient testing.
OpenResourceIdResult r = getResourceId(uri);
try {
InputStream stream = r.r.openRawResource(r.id);
return stream;
} catch (Resources.NotFoundException ex) {
throw new FileNotFoundException("Resource does not exist: " + uri);
}
} else if (SCHEME_FILE.equals(scheme)) {
// Note: left here to avoid breaking compatibility. May be removed
// with sufficient testing.
return new FileInputStream(uri.getPath());
} else {
AssetFileDescriptor fd = openAssetFileDescriptor(uri, "r");
try {
return fd != null ? fd.createInputStream() : null;
} catch (IOException e) {
throw new FileNotFoundException("Unable to create stream");
}
}
|
public final java.io.OutputStream | openOutputStream(android.net.Uri uri)Synonym for {@link #openOutputStream(Uri, String)
openOutputStream(uri, "w")}.
return openOutputStream(uri, "w");
|
public final java.io.OutputStream | openOutputStream(android.net.Uri uri, java.lang.String mode)Open a stream on to the content associated with a content URI. If there
is no data associated with the URI, FileNotFoundException is thrown.
Accepts the following URI schemes:
- content ({@link #SCHEME_CONTENT})
- file ({@link #SCHEME_FILE})
See {@link #openAssetFileDescriptor(Uri, String)} for more information
on these schemes.
AssetFileDescriptor fd = openAssetFileDescriptor(uri, mode);
try {
return fd != null ? fd.createOutputStream() : null;
} catch (IOException e) {
throw new FileNotFoundException("Unable to create stream");
}
|
public final android.database.Cursor | query(android.net.Uri uri, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sortOrder)Query the given URI, returning a {@link Cursor} over the result set.
IContentProvider provider = acquireProvider(uri);
if (provider == null) {
return null;
}
try {
Cursor qCursor = provider.query(uri, projection, selection, selectionArgs, sortOrder);
if(qCursor == null) {
releaseProvider(provider);
return null;
}
//Wrap the cursor object into CursorWrapperInner object
return new CursorWrapperInner(qCursor, provider);
} catch (RemoteException e) {
releaseProvider(provider);
return null;
} catch(RuntimeException e) {
releaseProvider(provider);
throw e;
}
|
public final void | registerContentObserver(android.net.Uri uri, boolean notifyForDescendents, android.database.ContentObserver observer)Register an observer class that gets callbacks when data identified by a
given content URI changes.
try {
ContentServiceNative.getDefault().registerContentObserver(uri, notifyForDescendents,
observer.getContentObserver());
} catch (RemoteException e) {
}
|
public abstract boolean | releaseProvider(IContentProvider icp)
|
public void | startSync(android.net.Uri uri, android.os.Bundle extras)Start an asynchronous sync operation. If you want to monitor the progress
of the sync you may register a SyncObserver. Only values of the following
types may be used in the extras bundle:
- Integer
- Long
- Boolean
- Float
- Double
- String
validateSyncExtrasBundle(extras);
try {
ContentServiceNative.getDefault().startSync(uri, extras);
} catch (RemoteException e) {
}
|
public final void | unregisterContentObserver(android.database.ContentObserver observer)Unregisters a change observer.
try {
IContentObserver contentObserver = observer.releaseContentObserver();
if (contentObserver != null) {
ContentServiceNative.getDefault().unregisterContentObserver(
contentObserver);
}
} catch (RemoteException e) {
}
|
public final int | update(android.net.Uri uri, ContentValues values, java.lang.String where, java.lang.String[] selectionArgs)Update row(s) in a content URI.
If the content provider supports transactions the update will be atomic.
IContentProvider provider = acquireProvider(uri);
if (provider == null) {
throw new IllegalArgumentException("Unknown URI " + uri);
}
try {
return provider.update(uri, values, where, selectionArgs);
} catch (RemoteException e) {
return -1;
} finally {
releaseProvider(provider);
}
|
public static void | validateSyncExtrasBundle(android.os.Bundle extras)Check that only values of the following types are in the Bundle:
- Integer
- Long
- Boolean
- Float
- Double
- String
- null
try {
for (String key : extras.keySet()) {
Object value = extras.get(key);
if (value == null) continue;
if (value instanceof Long) continue;
if (value instanceof Integer) continue;
if (value instanceof Boolean) continue;
if (value instanceof Float) continue;
if (value instanceof Double) continue;
if (value instanceof String) continue;
throw new IllegalArgumentException("unexpected value type: "
+ value.getClass().getName());
}
} catch (IllegalArgumentException e) {
throw e;
} catch (RuntimeException exc) {
throw new IllegalArgumentException("error unparceling Bundle", exc);
}
|