本文整理汇总了Java中android.content.ContentResolver类的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver类的具体用法?Java ContentResolver怎么用?Java ContentResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContentResolver类属于android.content包,在下文中一共展示了ContentResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CondomCore
import android.content.ContentResolver; //导入依赖的package包/类
CondomCore(final Context base, final CondomOptions options, final String tag) {
mBase = base;
DEBUG = (base.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
mExcludeBackgroundReceivers = options.mExcludeBackgroundReceivers;
mExcludeBackgroundServices = SDK_INT < O && options.mExcludeBackgroundServices;
mOutboundJudge = options.mOutboundJudge;
mDryRun = options.mDryRun;
mPackageManager = new Lazy<PackageManager>() { @Override protected PackageManager create() {
return new CondomPackageManager(CondomCore.this, base.getPackageManager(), tag);
}};
mContentResolver = new Lazy<ContentResolver>() { @Override protected ContentResolver create() {
return new CondomContentResolver(CondomCore.this, base, base.getContentResolver());
}};
final List<CondomKit> kits = options.mKits == null ? null : new ArrayList<>(options.mKits);
if (kits != null && ! kits.isEmpty()) {
mKitManager = new CondomKitManager();
for (final CondomKit kit : kits)
kit.onRegister(mKitManager);
} else mKitManager = null;
if (mDryRun) Log.w(tag, "Start dry-run mode, no outbound requests will be blocked actually, despite later stated in log.");
}
示例2: run
import android.content.ContentResolver; //导入依赖的package包/类
@Override
public void run(final Context context, final Callback callback) {
ConferenceDataHandler.resetDataTimestamp(context);
final Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
new AsyncTask<Context, Void, Void>() {
@Override
protected Void doInBackground(Context... contexts) {
Account account = AccountUtils.getActiveAccount(context);
if (account == null) {
callback.done(false, "Cannot sync if there is no active account.");
} else {
new SyncHelper(contexts[0]).performSync(new SyncResult(),
AccountUtils.getActiveAccount(context), bundle);
}
return null;
}
}.execute(context);
}
示例3: getRealFilePath
import android.content.ContentResolver; //导入依赖的package包/类
public static String getRealFilePath(final Context context, final Uri uri) {
if (null == uri) return null;
final String scheme = uri.getScheme();
String data = null;
if (scheme == null)
data = uri.getPath();
else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
data = uri.getPath();
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
final Cursor cursor = context.getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.DATA}, null, null, null);
if (null != cursor) {
if (cursor.moveToFirst()) {
final int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
if (index > -1) {
data = cursor.getString(index);
}
}
cursor.close();
}
}
return data;
}
示例4: openImageThumbnailCleared
import android.content.ContentResolver; //导入依赖的package包/类
protected ParcelFileDescriptor openImageThumbnailCleared(long id, CancellationSignal signal)
throws FileNotFoundException {
final ContentResolver resolver = getContext().getContentResolver();
Cursor cursor = null;
try {
cursor = resolver.query(Images.Thumbnails.EXTERNAL_CONTENT_URI,
ImageThumbnailQuery.PROJECTION, Images.Thumbnails.IMAGE_ID + "=" + id, null,
null);
if (cursor.moveToFirst()) {
final String data = cursor.getString(ImageThumbnailQuery._DATA);
return ParcelFileDescriptor.open(
new File(data), ParcelFileDescriptor.MODE_READ_ONLY);
}
} finally {
IoUtils.closeQuietly(cursor);
}
return null;
}
示例5: deleteFileFromMediaStore
import android.content.ContentResolver; //导入依赖的package包/类
private static void deleteFileFromMediaStore(final ContentResolver contentResolver, File file) {
String canonicalPath;
try {
canonicalPath = file.getCanonicalPath();
} catch (IOException e) {
canonicalPath = file.getAbsolutePath();
}
final Uri uri = MediaStore.Files.getContentUri("external");
final int result = contentResolver.delete(uri,
MediaStore.Files.FileColumns.DATA + "=?", new String[]{canonicalPath});
if (result == 0) {
final String absolutePath = file.getAbsolutePath();
if (!absolutePath.equals(canonicalPath)) {
contentResolver.delete(uri,
MediaStore.Files.FileColumns.DATA + "=?", new String[]{absolutePath});
}
}
}
示例6: markAsRead
import android.content.ContentResolver; //导入依赖的package包/类
/**
* Marke all the episodes of a season as Watched
* @param context
* @param season
*/
static public void markAsRead(final Context context, final Season season) {
final ContentResolver cr = context.getContentResolver();
Log.d(TAG, "markAsRead " + season.getName()+" S"+season.getSeasonNumber());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final boolean traktSync = Trakt.isTraktV2Enabled(context, prefs);
final ContentValues values = new ContentValues();
values.put(VideoStore.Video.VideoColumns.BOOKMARK, PlayerActivity.LAST_POSITION_END);
// TRAKT_DB_MARKED must not be marked here or TraktService would think it is already synchronized
// But if there uis not trakt sync we want to have the flag in the UI as well, hence we write it here ourselves!
if (!traktSync) {
values.put(VideoStore.Video.VideoColumns.ARCHOS_TRAKT_SEEN, Trakt.TRAKT_DB_MARKED);
}
final String where = "_id IN (SELECT video_id FROM episode e JOIN show s ON e.show_episode=s._id WHERE s._id=? AND e.season_episode=?)";
final String[] selectionArgs = new String[]{Long.toString(season.getShowId()), Integer.toString(season.getSeasonNumber())};
cr.update(VideoStore.Video.Media.EXTERNAL_CONTENT_URI, values, where, selectionArgs);
if (traktSync) {
syncTrakt(context, season);
}
}
示例7: saveMediaStore
import android.content.ContentResolver; //导入依赖的package包/类
/**
* save image to MediaStore.
*/
public void saveMediaStore(final ContentResolver cr) {
BoxingExecutor.getInstance().runWorker(new Runnable() {
@Override
public void run() {
if (cr != null && !TextUtils.isEmpty(getId())) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, getId());
values.put(MediaStore.Images.Media.MIME_TYPE, getMimeType());
values.put(MediaStore.Images.Media.DATA, getPath());
cr.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
}
}
});
}
示例8: getCustomSound
import android.content.ContentResolver; //导入依赖的package包/类
private static Uri getCustomSound(JSONObject gcmBundle) {
int soundId;
String sound = gcmBundle.optString("sound", "");
if (!TextUtils.isEmpty(sound) && sound.contains(".")) {
String[] str = sound.split(".");
sound = str.length < 1 ? "vitrinova" : str[0];
}
if (isValidResourceName(sound)) {
soundId = contextResources.getIdentifier(sound, "raw", packageName);
if (soundId != 0) {
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + packageName + "/" + soundId);
}
}
soundId = contextResources.getIdentifier("vitrinova", "raw", packageName);
if (soundId != 0) {
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + packageName + "/" + soundId);
}
return null;
}
示例9: getDocumentThumbnail
import android.content.ContentResolver; //导入依赖的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);
}
}
示例10: processFile
import android.content.ContentResolver; //导入依赖的package包/类
private final void processFile (String file, ContentResolver cr) {
String[] selectionArgs = new String[] { file };
long fileId = -1;
int scraperId = -1;
Cursor c = cr.query(Video.Media.getContentUriForPath(file),
PROJECTION, SELECTION, selectionArgs, null);
if (c != null) {
if (c.moveToFirst()) {
fileId = c.getLong(0);
scraperId = c.getInt(1);
}
c.close();
}
ScrapeDetailResult result = null;
if (fileId > 0) {
if (mForceUpdate || scraperId == 0)
result = mHost.getDefaultContentAutoDetails(file);
}
if (result != null && result.isOkay()) {
result.tag.save(mContext_, fileId);
}
}
示例11: getUrlByIntent
import android.content.ContentResolver; //导入依赖的package包/类
public static String getUrlByIntent(Context mContext, Intent mdata) {
Uri uri = mdata.getData();
String scheme = uri.getScheme();
String data = "";
if (scheme == null)
data = uri.getPath();
else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
data = uri.getPath();
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
Cursor cursor = mContext.getContentResolver().query(uri,
new String[]{MediaStore.Images.ImageColumns.DATA},
null, null, null);
if (null != cursor) {
if (cursor.moveToFirst()) {
int index = cursor.getColumnIndex(
MediaStore.Images.ImageColumns.DATA);
if (index > -1) {
data = cursor.getString(index);
}
}
cursor.close();
}
}
return data;
}
示例12: getRealPathFromUri
import android.content.ContentResolver; //导入依赖的package包/类
/**
* Get the path of a file from the Uri.
*
* @param contentResolver the content resolver which will query for the source file
* @param srcUri The source uri
* @return The Path for the file or null if doesn't exists
*/
@Nullable
public static String getRealPathFromUri(ContentResolver contentResolver, final Uri srcUri) {
String result = null;
if (isLocalContentUri(srcUri)) {
Cursor cursor = null;
try {
cursor = contentResolver.query(srcUri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
if (idx != -1) {
result = cursor.getString(idx);
}
}
} finally {
if (cursor != null) {
cursor.close();
}
}
} else if (isLocalFileUri(srcUri)) {
result = srcUri.getPath();
}
return result;
}
示例13: getMimeType
import android.content.ContentResolver; //导入依赖的package包/类
/**
* To find out the extension of required object in given uri
* Solution by http://stackoverflow.com/a/36514823/1171484
*/
public static String getMimeType(Activity context, Uri uri) {
String extension;
//Check uri format to avoid null
if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
//If scheme is a content
extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
if (TextUtils.isEmpty(extension))extension=MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
} else {
//If scheme is a File
//This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file name with spaces and special characters.
extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
if (TextUtils.isEmpty(extension))extension=MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
}
if(TextUtils.isEmpty(extension)){
extension=getMimeTypeByFileName(TUriParse.getFileWithUri(uri,context).getName());
}
return extension;
}
示例14: getRealFilePath
import android.content.ContentResolver; //导入依赖的package包/类
/**
* 根据文件Uri获取文件路径
* @param context
* @param uri
* @return the file path or null
*/
public static String getRealFilePath(final Context context, final Uri uri ) {
if ( null == uri ) return null;
final String scheme = uri.getScheme();
String path = null;
if ( scheme == null )
path = uri.getPath();
else if ( ContentResolver.SCHEME_FILE.equals( scheme ) ) {
path = uri.getPath();
} else if ( ContentResolver.SCHEME_CONTENT.equals( scheme ) ) {
Cursor cursor = context.getContentResolver().query( uri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null );
if ( null != cursor ) {
if ( cursor.moveToFirst() ) {
int index = cursor.getColumnIndex( MediaStore.Images.ImageColumns.DATA );
if ( index > -1 ) {
path = cursor.getString( index );
}
}
cursor.close();
}
}
return path;
}
示例15: onUncompressDocuments
import android.content.ContentResolver; //导入依赖的package包/类
public boolean onUncompressDocuments(ArrayList<DocumentInfo> docs) {
final Context context = getActivity();
final ContentResolver resolver = context.getContentResolver();
boolean hadTrouble = false;
for (DocumentInfo doc : docs) {
if (!doc.isArchiveSupported()) {
Log.w(TAG, "Skipping " + doc);
hadTrouble = true;
continue;
}
try {
hadTrouble = ! DocumentsContract.uncompressDocument(resolver, doc.derivedUri);
} catch (Exception e) {
Log.w(TAG, "Failed to Uncompress " + doc);
CrashReportingManager.logException(e);
hadTrouble = true;
}
}
return hadTrouble;
}