本文整理汇总了Java中android.content.ContentResolver.openInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver.openInputStream方法的具体用法?Java ContentResolver.openInputStream怎么用?Java ContentResolver.openInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentResolver
的用法示例。
在下文中一共展示了ContentResolver.openInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
public Point init(Context context, Uri uri) throws Exception {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inJustDecodeBounds = false;
ContentResolver resolver = context.getContentResolver();
InputStream inputStream = resolver.openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
String filename = String.valueOf(uri.toString().hashCode());
cacheFile = new File(context.getCacheDir(), filename);
FileOutputStream fileOutputStream = new FileOutputStream(cacheFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, JPEG_QUALITY, fileOutputStream);
decoder = new CustomRegionDecoder();
return decoder.init(context, Uri.fromFile(cacheFile));
}
示例2: loadImage
import android.content.ContentResolver; //导入方法依赖的package包/类
private boolean loadImage(Uri uri, boolean verbose) {
ContentResolver resolver = getContentResolver();
InputStream stream = null;
if (uri != null) {
mSettings.setImageUri(uri);
try {
stream = resolver.openInputStream(uri);
} catch (Exception ex) { // e.g. FileNotFoundException, SecurityException
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isPermissionException(ex)
&& needsRequestReadPermission()) {
requestReadPermission(REQUEST_LOAD_IMAGE_PERMISSION);
return false;
}
showFileNotLoadedMessage(ex, verbose);
}
}
if (stream == null || !loadImage(stream, resolver, uri)) {
setDefaultBitmap();
return false;
}
return true;
}
示例3: loadResourceFromUri
import android.content.ContentResolver; //导入方法依赖的package包/类
private InputStream loadResourceFromUri(Uri uri, ContentResolver contentResolver)
throws FileNotFoundException {
switch (URI_MATCHER.match(uri)) {
case ID_CONTACTS_CONTACT:
return openContactPhotoInputStream(contentResolver, uri);
case ID_CONTACTS_LOOKUP:
// If it was a Lookup uri then resolve it first, then continue loading the contact uri.
uri = ContactsContract.Contacts.lookupContact(contentResolver, uri);
if (uri == null) {
throw new FileNotFoundException("Contact cannot be found");
}
return openContactPhotoInputStream(contentResolver, uri);
case ID_CONTACTS_THUMBNAIL:
case ID_CONTACTS_PHOTO:
case UriMatcher.NO_MATCH:
default:
return contentResolver.openInputStream(uri);
}
}
示例4: getStreamFromContent
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Retrieves {@link InputStream} of image by URI (image is accessed using {@link ContentResolver}).
*
* @param imageUri Image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
* DisplayImageOptions.extraForDownloader(Object)}; can be null
* @return {@link InputStream} of image
* @throws FileNotFoundException if the provided URI could not be opened
*/
protected InputStream getStreamFromContent(String imageUri, Object extra) throws FileNotFoundException {
ContentResolver res = context.getContentResolver();
Uri uri = Uri.parse(imageUri);
if (isVideoContentUri(uri)) { // video thumbnail
Long origId = Long.valueOf(uri.getLastPathSegment());
Bitmap bitmap = MediaStore.Video.Thumbnails
.getThumbnail(res, origId, MediaStore.Images.Thumbnails.MINI_KIND, null);
if (bitmap != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, bos);
return new ByteArrayInputStream(bos.toByteArray());
}
} else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) { // contacts photo
return getContactPhotoStream(uri);
}
return res.openInputStream(uri);
}
示例5: getStreamFromContent
import android.content.ContentResolver; //导入方法依赖的package包/类
protected InputStream getStreamFromContent(String imageUri, Object extra) throws
FileNotFoundException {
ContentResolver res = this.context.getContentResolver();
Uri uri = Uri.parse(imageUri);
if (isVideoContentUri(uri)) {
Bitmap bitmap = Thumbnails.getThumbnail(res, Long.valueOf(uri.getLastPathSegment())
.longValue(), 1, null);
if (bitmap != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, bos);
return new ByteArrayInputStream(bos.toByteArray());
}
} else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) {
return getContactPhotoStream(uri);
}
return res.openInputStream(uri);
}
示例6: decode
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* @description:解析Bitmap的公用方法.注意各个方法的参数必须要有options
* @author:hui-ye
* @param path
* @param data
* @param context
* @param uri
* @param options
* @return:
*/
public static Bitmap decode(String path, byte[] data, Context context, Uri uri,
Options options) throws Exception {
Bitmap bitmap = null;
if (path != null) {
bitmap = BitmapFactory.decodeFile(path, options);
} else if (data != null) {
BitmapFactory.decodeByteArray(data, 0, data.length, options);
} else if (uri != null) {
// uri不为空的时候context也不要为空.:ContentResolver;Uri内容解析器
ContentResolver resolver = context.getContentResolver();
InputStream is;
is = resolver.openInputStream(uri);
bitmap = BitmapFactory.decodeStream(is, null, options);
}
System.gc();
return bitmap;
}
示例7: decodeImage
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Decode image from uri using given "inSampleSize", but if failed due to out-of-memory then raise
* the inSampleSize until success.
*/
private static Bitmap decodeImage(
ContentResolver resolver, Uri uri, BitmapFactory.Options options)
throws FileNotFoundException {
do {
InputStream stream = null;
try {
stream = resolver.openInputStream(uri);
return BitmapFactory.decodeStream(stream, EMPTY_RECT, options);
} catch (OutOfMemoryError e) {
options.inSampleSize *= 2;
} finally {
closeSafe(stream);
}
} while (options.inSampleSize <= 512);
throw new RuntimeException("Failed to decode image: " + uri);
}
示例8: getImageRadio
import android.content.ContentResolver; //导入方法依赖的package包/类
public static float getImageRadio(ContentResolver resolver, Uri fileUri) {
InputStream inputStream = null;
try {
inputStream = resolver.openInputStream(fileUri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, options);
int initWidth = options.outWidth;
int initHeight = options.outHeight;
float rate = initHeight > initWidth ? (float) initHeight / (float) initWidth
: (float) initWidth / (float) initHeight;
return rate;
} catch (Exception e) {
e.printStackTrace();
return 1;
} finally {
IOUtils.closeIO(inputStream);
}
}
示例9: shouldInterceptRequest
import android.content.ContentResolver; //导入方法依赖的package包/类
protected WebResourceResponse shouldInterceptRequest(WebView webView, Uri uri) {
if (!CID_SCHEME.equals(uri.getScheme())) {
return RESULT_DO_NOT_INTERCEPT;
}
if (attachmentResolver == null) {
return RESULT_DUMMY_RESPONSE;
}
String cid = uri.getSchemeSpecificPart();
if (TextUtils.isEmpty(cid)) {
return RESULT_DUMMY_RESPONSE;
}
Uri attachmentUri = attachmentResolver.getAttachmentUriForContentId(cid);
if (attachmentUri == null) {
return RESULT_DUMMY_RESPONSE;
}
Context context = webView.getContext();
ContentResolver contentResolver = context.getContentResolver();
try {
String mimeType = contentResolver.getType(attachmentUri);
InputStream inputStream = contentResolver.openInputStream(attachmentUri);
WebResourceResponse webResourceResponse = new WebResourceResponse(mimeType, null, inputStream);
addCacheControlHeader(webResourceResponse);
return webResourceResponse;
} catch (Exception e) {
Timber.e(e, "Error while intercepting URI: %s", uri);
return RESULT_DUMMY_RESPONSE;
}
}
示例10: getStreamFromContent
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Retrieves {@link InputStream} of image by URI (image is accessed using {@link ContentResolver}).
*
* @param imageUri Image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
* DisplayImageOptions.extraForDownloader(Object)}; can be null
* @return {@link InputStream} of image
* @throws FileNotFoundException if the provided URI could not be opened
*/
protected InputStream getStreamFromContent(String imageUri, Object extra) throws FileNotFoundException {
ContentResolver res = context.getContentResolver();
Uri uri = Uri.parse(imageUri);
//return res.openInputStream(uri);
if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) {
return ContactsContract.Contacts.openContactPhotoInputStream(res, uri);
} else {
return res.openInputStream(uri);
}
}
示例11: decode
import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
public Bitmap decode(Context context, Uri uri) throws Exception {
boolean use8BitColor = Settings.getInstance(context).use8BitColor();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = use8BitColor ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
ContentResolver resolver = context.getContentResolver();
InputStream inputStream = resolver.openInputStream(uri);
return BitmapFactory.decodeStream(inputStream, null, options);
}
示例12: decodeImage
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Decode image from uri using given "inSampleSize", but if failed due to out-of-memory then raise
* the inSampleSize until success.
*/
private static Bitmap decodeImage(ContentResolver resolver, Uri uri, BitmapFactory.Options options) throws FileNotFoundException {
do {
InputStream stream = null;
try {
stream = resolver.openInputStream(uri);
return BitmapFactory.decodeStream(stream, EMPTY_RECT, options);
} catch (OutOfMemoryError e) {
options.inSampleSize *= 2;
} finally {
closeSafe(stream);
}
} while (options.inSampleSize <= 512);
throw new RuntimeException("Failed to decode image: " + uri);
}
示例13: isUriRequiresPermissions
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Test if we can open the given Android URI to test if permission required error is thrown.<br>
* Only relevant for API version 23 and above.
*
* @param context used to access Android APIs, like content resolve, it is your activity/fragment/widget.
* @param uri the result URI of image pick.
*/
public static boolean isUriRequiresPermissions(@NonNull Context context, @NonNull Uri uri) {
try {
ContentResolver resolver = context.getContentResolver();
InputStream stream = resolver.openInputStream(uri);
if (stream != null) {
stream.close();
}
return false;
} catch (Exception e) {
return true;
}
}
示例14: openThumbInputStream
import android.content.ContentResolver; //导入方法依赖的package包/类
private InputStream openThumbInputStream() throws FileNotFoundException {
ContentResolver contentResolver = MusicApplication.getContext().getContentResolver();
Uri thumbnailUri;
switch (mCategory) {
case Constants.CATEGORY_RECENTLY_ADDED:
thumbnailUri = Utils.getAlbumArtUri(SongsPresenter.getSongsForCursor(
RecentlyAddedPresenter.makeLastAddedCursor(), true).get(0).mAlbumId);
break;
case Constants.CATEGORY_RECENTLY_PLAYED:
thumbnailUri = Utils.getAlbumArtUri(SongsPresenter.getSongsForCursor(
RecentlyPlayPresenter.makeRecentPlayCursor(), true).get(0).mAlbumId);
break;
case Constants.CATEGORY_MY_FAVORITE:
thumbnailUri = Utils.getAlbumArtUri(SongsPresenter.getSongsForCursor(
MyFavoritePresenter.getFavoriteSongCursor(), true).get(0).mAlbumId);
break;
default:
thumbnailUri = Utils.getAlbumArtUri(AlbumsPresenter.getArtistAlbums(
Integer.parseInt(mCategory)).get(0).getAlbumId());
break;
}
try {
mInputStream = contentResolver.openInputStream(thumbnailUri);
} catch (NullPointerException e) {
throw (FileNotFoundException)
new FileNotFoundException("NPE opening uri: " + thumbnailUri).initCause(e);
}
return mInputStream;
}
示例15: decodeImageForOption
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Decode image from uri using "inJustDecodeBounds" to get the image dimensions.
*/
private static BitmapFactory.Options decodeImageForOption(ContentResolver resolver, Uri uri) throws FileNotFoundException {
InputStream stream = null;
try {
stream = resolver.openInputStream(uri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(stream, EMPTY_RECT, options);
options.inJustDecodeBounds = false;
return options;
} finally {
closeSafe(stream);
}
}