當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。