当前位置: 首页>>代码示例>>Java>>正文


Java ContentResolver.openInputStream方法代码示例

本文整理汇总了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));
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:19,代码来源:RAWImageBitmapRegionDecoder.java

示例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;
}
 
开发者ID:olgamiller,项目名称:SSTVEncoder2,代码行数:23,代码来源:MainActivity.java

示例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);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:StreamLocalUriFetcher.java

示例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);
}
 
开发者ID:siwangqishiq,项目名称:ImageLoaderSupportGif,代码行数:29,代码来源:BaseImageDownloader.java

示例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);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:18,代码来源:BaseImageDownloader.java

示例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;
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:29,代码来源:BitmapUtil.java

示例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);
}
 
开发者ID:prashantsaini1,项目名称:android-titanium-imagecropper,代码行数:21,代码来源:BitmapUtils.java

示例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);
    }

}
 
开发者ID:Sherchen,项目名称:AnimationsDemo,代码行数:21,代码来源:ImageUtils.java

示例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;
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:34,代码来源:K9WebViewClient.java

示例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);
		}
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:20,代码来源:BaseImageDownloader.java

示例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);
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:11,代码来源:CustomImageDecoder.java

示例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);
}
 
开发者ID:garretyoder,项目名称:Cluttr,代码行数:19,代码来源:BitmapUtils.java

示例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;
    }
}
 
开发者ID:garretyoder,项目名称:Cluttr,代码行数:20,代码来源:CropImage.java

示例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;
}
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:35,代码来源:ArtworkDataFetcher.java

示例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);
    }
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:17,代码来源:BitmapUtils.java


注:本文中的android.content.ContentResolver.openInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。