本文整理匯總了Java中android.content.ContentProviderClient類的典型用法代碼示例。如果您正苦於以下問題:Java ContentProviderClient類的具體用法?Java ContentProviderClient怎麽用?Java ContentProviderClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ContentProviderClient類屬於android.content包,在下文中一共展示了ContentProviderClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDocumentThumbnail
import android.content.ContentProviderClient; //導入依賴的package包/類
/**
* Return thumbnail representing the document at the given URI. Callers are
* responsible for their own in-memory caching.
*
* @param documentUri document to return thumbnail for, which must have
* {@link Document#FLAG_SUPPORTS_THUMBNAIL} set.
* @param size optimal thumbnail size desired. A provider may return a
* thumbnail of a different size, but never more than double the
* requested size.
* @param signal signal used to indicate if caller is no longer interested
* in the thumbnail.
* @return decoded thumbnail, or {@code null} if problem was encountered.
* @see DocumentsProvider#openDocumentThumbnail(String, Point,
* CancellationSignal)
*/
public static Bitmap getDocumentThumbnail(
ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal) {
final ContentProviderClient client = ContentProviderClientCompat.acquireUnstableContentProviderClient(resolver,
documentUri.getAuthority());
try {
if(UsbStorageProvider.AUTHORITY.equals(documentUri.getAuthority())) {
return ImageUtils.getThumbnail(resolver, documentUri, size.x, size.y);
}
return getDocumentThumbnails(client, documentUri, size, signal);
} catch (Exception e) {
if (!(e instanceof OperationCanceledException)) {
Log.w(TAG, "Failed to load thumbnail for " + documentUri + ": " + e);
}
return null;
} finally {
ContentProviderClientCompat.releaseQuietly(client);
}
}
示例2: uncompressDocument
import android.content.ContentProviderClient; //導入依賴的package包/類
public static boolean uncompressDocument(ContentResolver resolver, Uri fromDocumentUri) {
final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
fromDocumentUri.getAuthority());
try {
final Bundle in = new Bundle();
in.putString(Document.COLUMN_DOCUMENT_ID, getDocumentId(fromDocumentUri));
in.putParcelable(DocumentsContract.EXTRA_URI, fromDocumentUri);
resolver.call(fromDocumentUri, METHOD_UNCOMPRESS_DOCUMENT, null, in);
return true;
} catch (Exception e) {
Log.w(TAG, "Failed to uncompress document", e);
return false;
} finally {
ContentProviderClientCompat.releaseQuietly(client);
}
}
示例3: doInBackground
import android.content.ContentProviderClient; //導入依賴的package包/類
@Override
protected Uri doInBackground(Void... params) {
final ContentResolver resolver = getContentResolver();
final DocumentInfo cwd = getCurrentDirectory();
ContentProviderClient client = null;
Uri childUri = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(
resolver, cwd.derivedUri.getAuthority());
childUri = DocumentsContract.createDocument(
resolver, cwd.derivedUri, mMimeType, mDisplayName);
} catch (Exception e) {
Log.w(TAG, "Failed to create document", e);
} finally {
ContentProviderClientCompat.releaseQuietly(client);
}
if (childUri != null) {
saveStackBlocking();
}
return childUri;
}
示例4: doInBackground
import android.content.ContentProviderClient; //導入依賴的package包/類
@Override
protected Uri doInBackground(Void... params) {
final ContentResolver resolver = mActivity.getContentResolver();
ContentProviderClient client = null;
Uri childUri = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(
resolver, mCwd.derivedUri.getAuthority());
childUri = DocumentsContract.createDocument(
resolver, mCwd.derivedUri, mMimeType, mDisplayName);
} catch (Exception e) {
Log.w(DocumentsActivity.TAG, "Failed to create document", e);
CrashReportingManager.logException(e);
} finally {
ContentProviderClientCompat.releaseQuietly(client);
}
return childUri;
}
示例5: doInBackground
import android.content.ContentProviderClient; //導入依賴的package包/類
@Override
protected DocumentInfo doInBackground(Void... params) {
final ContentResolver resolver = mActivity.getContentResolver();
ContentProviderClient client = null;
try {
final Uri childUri = DocumentsContract.renameDocument(
resolver, mDoc.derivedUri, mFileName);
return DocumentInfo.fromUri(resolver, childUri);
} catch (Exception e) {
Log.w(TAG, "Failed to rename directory", e);
CrashReportingManager.logException(e);
return null;
} finally {
ContentProviderClientCompat.releaseQuietly(client);
}
}
示例6: doInBackground
import android.content.ContentProviderClient; //導入依賴的package包/類
@Override
protected DocumentInfo doInBackground(Void... params) {
final ContentResolver resolver = mActivity.getContentResolver();
ContentProviderClient client = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mCwd.derivedUri.getAuthority());
final Uri childUri = DocumentsContract.createDocument(
resolver, mCwd.derivedUri, Document.MIME_TYPE_DIR, mDisplayName);
return DocumentInfo.fromUri(resolver, childUri);
} catch (Exception e) {
Log.w(TAG, "Failed to create directory", e);
CrashReportingManager.logException(e);
return null;
} finally {
ContentProviderClientCompat.releaseQuietly(client);
}
}
示例7: runInternal
import android.content.ContentProviderClient; //導入依賴的package包/類
public void runInternal() {
ContentProviderClient client = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(
getContext().getContentResolver(), authority);
final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootId);
final Cursor cursor = client.query(
uri, null, null, null, DirectoryLoader.getQuerySortOrder(mSortOrder));
mWithRoot = new RootCursorWrapper(authority, rootId, cursor, MAX_DOCS_FROM_ROOT);
} catch (Exception e) {
Log.w(TAG, "Failed to load " + authority + ", " + rootId, e);
} finally {
ContentProviderClientCompat.releaseQuietly(client);
}
set(mWithRoot);
mFirstPassLatch.countDown();
if (mFirstPassDone) {
onContentChanged();
}
}
示例8: onPerformSync
import android.content.ContentProviderClient; //導入依賴的package包/類
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
SyncResult syncResult) {
// required for dav4android (ServiceLoader)
Thread.currentThread().setContextClassLoader(getContext().getClassLoader());
try {
syncLocalAndRemoteCollections(account, provider);
syncCalendarsEvents(account, provider, extras);
// notify any registered caller that sync operation is finished
getContext().getContentResolver().notifyChange(GlobalConstant.CONTENT_URI, null, false);
} catch (InvalidAccountException | CalendarStorageException e) {
e.printStackTrace();
}
}
示例9: onPerformSync
import android.content.ContentProviderClient; //導入依賴的package包/類
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
if ( Utility.isNotDuplicateSync(getContext())) {
if (BuildConfig.DEBUG) Log.d(LOG_TAG,"Start sync!");
sendSyncStatus(START_SYNC);
final TvService service = TvApiClient.getClient().create(TvService.class);
syncCategories(service, provider, syncResult);
syncChannels(service, provider, syncResult);
syncPrograms(service, provider, syncResult);
notifyTvGuide(syncResult.stats.numInserts, syncResult.stats.numIoExceptions);
prefHelper.setLastSyncTime(getContext().getString(R.string.pref_last_sync_time_key),
System.currentTimeMillis());
prefHelper.setFirstRun(getContext().getString(R.string.pref_fist_run_key),false);
sendSyncStatus(END_SYNC);
if (BuildConfig.DEBUG) Log.d(LOG_TAG,"End sync!");
}
}
示例10: updateFromUri
import android.content.ContentProviderClient; //導入依賴的package包/類
public void updateFromUri(ContentResolver resolver, Uri uri) throws FileNotFoundException {
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(
resolver, uri.getAuthority());
cursor = client.query(uri, null, null, null, null);
if (!cursor.moveToFirst()) {
throw new FileNotFoundException("Missing details for " + uri);
}
updateFromCursor(cursor, uri.getAuthority());
} catch (Throwable t) {
throw asFileNotFoundException(t);
} finally {
IoUtils.closeQuietly(cursor);
ContentProviderClientCompat.releaseQuietly(client);
}
}
示例11: doInBackground
import android.content.ContentProviderClient; //導入依賴的package包/類
@Override
protected Uri doInBackground(Void... params) {
final ContentResolver resolver = getContentResolver();
final DocumentInfo cwd = getCurrentDirectory();
ContentProviderClient client = null;
Uri childUri = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(
resolver, cwd.derivedUri.getAuthority());
childUri = DocumentsContract.createDocument(
resolver, cwd.derivedUri, mMimeType, mDisplayName);
} catch (Exception e) {
Log.w(TAG, "Failed to create document", e);
CrashReportingManager.logException(e);
} finally {
ContentProviderClientCompat.releaseQuietly(client);
}
if (childUri != null) {
saveStackBlocking();
}
return childUri;
}
示例12: isChildDocument
import android.content.ContentProviderClient; //導入依賴的package包/類
public static boolean isChildDocument(ContentProviderClient client, Uri parentDocumentUri,
Uri childDocumentUri) throws RemoteException {
final Bundle in = new Bundle();
in.putParcelable(DocumentsContract.EXTRA_URI, parentDocumentUri);
in.putParcelable(DocumentsContract.EXTRA_TARGET_URI, childDocumentUri);
final Bundle out = client.call(METHOD_IS_CHILD_DOCUMENT, null, in);
if (out == null) {
throw new RemoteException("Failed to get a reponse from isChildDocument query.");
}
if (!out.containsKey(DocumentsContract.EXTRA_RESULT)) {
throw new RemoteException("Response did not include result field..");
}
return out.getBoolean(DocumentsContract.EXTRA_RESULT);
}
示例13: onPerformSync
import android.content.ContentProviderClient; //導入依賴的package包/類
/**
* Called by the Android system in response to a request to run the sync adapter. The work
* required to read data from the network, parse it, and store it in the content provider
* should be done here. Extending AbstractThreadedSyncAdapter ensures that all methods within SyncAdapter
* run on a background thread. For this reason, blocking I/O and other long-running tasks can be
* run <em>in situ</em>, and you don't have to set up a separate thread for them.
*
* <p>
* <p>This is where we actually perform any work required to perform a sync.
* {@link AbstractThreadedSyncAdapter} guarantees that this will be called on a non-UI thread,
* so it is safe to perform blocking I/O here.
* <p>
*
* <p>The syncResult argument allows you to pass information back to the method that triggered
* the sync.
*/
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
// Your code to sync data
// between mobile database and
// the server goes here.
for (int i = 0; i < 15; i++) {
try {
Thread.sleep(1000);
Log.i(TAG, ">>>> sleeping the thread: " + (i + 1));
} catch (InterruptedException e) {
e.printStackTrace();
}
} // end for
// write DB data sanity checks at the end.
}
示例14: query
import android.content.ContentProviderClient; //導入依賴的package包/類
/**
* 調用插件裏的Provider
*
* @see android.content.ContentProviderClient#query(Uri, String[], String, String[], String)
*/
public static Cursor query(Context c, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
ContentProviderClient client = PluginProviderClient.acquireContentProviderClient(c, "");
if (client != null) {
try {
Uri toUri = toCalledUri(c, uri);
return client.query(toUri, projection, selection, selectionArgs, sortOrder);
} catch (RemoteException e) {
if (LogDebug.LOG) {
Log.d(TAG, e.toString());
}
}
}
if (LogDebug.LOG) {
Log.d(TAG, String.format("call query1 %s fail", uri.toString()));
}
return null;
}
示例15: update
import android.content.ContentProviderClient; //導入依賴的package包/類
/**
* 調用插件裏的Provider
*
* @see android.content.ContentProviderClient#update(Uri, ContentValues, String, String[])
*/
public static int update(Context c, Uri uri, ContentValues values, String selection, String[] selectionArgs) {
ContentProviderClient client = PluginProviderClient.acquireContentProviderClient(c, "");
if (client != null) {
try {
Uri toUri = toCalledUri(c, uri);
return client.update(toUri, values, selection, selectionArgs);
} catch (RemoteException e) {
if (LogDebug.LOG) {
Log.d(TAG, e.toString());
}
}
}
if (LogDebug.LOG) {
Log.d(TAG, String.format("call update %s", uri.toString()));
}
return -1;
}