當前位置: 首頁>>代碼示例>>Java>>正文


Java ContentResolver.openAssetFileDescriptor方法代碼示例

本文整理匯總了Java中android.content.ContentResolver.openAssetFileDescriptor方法的典型用法代碼示例。如果您正苦於以下問題:Java ContentResolver.openAssetFileDescriptor方法的具體用法?Java ContentResolver.openAssetFileDescriptor怎麽用?Java ContentResolver.openAssetFileDescriptor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.ContentResolver的用法示例。


在下文中一共展示了ContentResolver.openAssetFileDescriptor方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setDataSource

import android.content.ContentResolver; //導入方法依賴的package包/類
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
    SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
  setDataSource(uri.toString());
  return;
}
 
開發者ID:Leavessilent,項目名稱:QuanMinTV,代碼行數:25,代碼來源:MediaMetadataRetriever.java

示例2: setDataSource

import android.content.ContentResolver; //導入方法依賴的package包/類
public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  setDataSource(uri.toString(), headers);
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:22,代碼來源:MediaPlayer.java

示例3: loadResource

import android.content.ContentResolver; //導入方法依賴的package包/類
@Override
protected ParcelFileDescriptor loadResource(Uri uri, ContentResolver contentResolver)
    throws FileNotFoundException {
  AssetFileDescriptor assetFileDescriptor = contentResolver.openAssetFileDescriptor(uri, "r");
  if (assetFileDescriptor == null) {
    throw new FileNotFoundException("FileDescriptor is null for: " + uri);
  }
  return assetFileDescriptor.getParcelFileDescriptor();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:FileDescriptorLocalUriFetcher.java

示例4: putImageInfo

import android.content.ContentResolver; //導入方法依賴的package包/類
private static boolean putImageInfo(
    ContentResolver resolver,
    Cursor photos,
    WritableMap node,
    int idIndex,
    int widthIndex,
    int heightIndex) {
  WritableMap image = new WritableNativeMap();
  Uri photoUri = Uri.withAppendedPath(
      Images.Media.EXTERNAL_CONTENT_URI,
      photos.getString(idIndex));
  image.putString("uri", photoUri.toString());
  float width = -1;
  float height = -1;
  if (IS_JELLY_BEAN_OR_LATER) {
    width = photos.getInt(widthIndex);
    height = photos.getInt(heightIndex);
  }
  if (width <= 0 || height <= 0) {
    try {
      AssetFileDescriptor photoDescriptor = resolver.openAssetFileDescriptor(photoUri, "r");
      BitmapFactory.Options options = new BitmapFactory.Options();
      // Set inJustDecodeBounds to true so we don't actually load the Bitmap, but only get its
      // dimensions instead.
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFileDescriptor(photoDescriptor.getFileDescriptor(), null, options);
      photoDescriptor.close();

      width = options.outWidth;
      height = options.outHeight;
    } catch (IOException e) {
      FLog.e(ReactConstants.TAG, "Could not get width/height for " + photoUri.toString(), e);
      return false;
    }
  }
  image.putDouble("width", width);
  image.putDouble("height", height);
  node.putMap("image", image);
  return true;
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:41,代碼來源:CameraRollManager.java

示例5: onActivityResult

import android.content.ContentResolver; //導入方法依賴的package包/類
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode != RESULT_OK) {
        if (mCurrentTaskToAttachImage != null)
            mCurrentTaskToAttachImage = null;
        return;
    }

    final int size = THUMBNAIL_SIZE;
    Bitmap thumbnail = null;
    if (requestCode == REQUEST_TAKE_PHOTO) {
        File file = new File(mImagePathToBeAttached);
        if (file.exists()) {
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(mImagePathToBeAttached, options);
            options.inJustDecodeBounds = false;
            mImageToBeAttached = BitmapFactory.decodeFile(mImagePathToBeAttached, options);
            if (mCurrentTaskToAttachImage == null) {
                thumbnail = ThumbnailUtils.extractThumbnail(mImageToBeAttached, size, size);
            }

            // Delete the temporary image file
            file.delete();
        }
        mImagePathToBeAttached = null;
    } else if (requestCode == REQUEST_CHOOSE_PHOTO) {
        try {
            Uri uri = data.getData();
            ContentResolver resolver = getContentResolver();
            mImageToBeAttached = MediaStore.Images.Media.getBitmap(resolver, uri);
            if (mCurrentTaskToAttachImage == null) {
                AssetFileDescriptor asset = resolver.openAssetFileDescriptor(uri, "r");
                thumbnail = ImageUtil.thumbnailFromDescriptor(asset.getFileDescriptor(), size, size);
            }
        } catch (IOException e) {
            Log.e(Application.TAG, "Cannot get a selected photo from the gallery.", e);
        }
    }

    if (mImageToBeAttached != null) {
        if (mCurrentTaskToAttachImage != null) {
            attachImage(mCurrentTaskToAttachImage, mImageToBeAttached);
            mImageToBeAttached = null;
        }
    }

    if (thumbnail != null) {
        ImageView imageView = (ImageView) findViewById(R.id.image);
        imageView.setImageBitmap(thumbnail);
    }

    // Ensure resetting the task to attach an image
    if (mCurrentTaskToAttachImage != null)
        mCurrentTaskToAttachImage = null;
}
 
開發者ID:Kaufland,項目名稱:andcouchbaseentity,代碼行數:59,代碼來源:TaskActivity.java

示例6: setDataSource

import android.content.ContentResolver; //導入方法依賴的package包/類
public void setDataSource(Context context, Uri uri)
    throws IllegalArgumentException, SecurityException {
    if (uri == null) {
        throw new IllegalArgumentException();
    }
    
    String scheme = uri.getScheme();
    if (SmbProxy.needToStream(scheme)){
        mSmbProxy = SmbProxy.setDataSource(uri, this, null);
        return;
    }
    if(scheme == null || scheme.equals("file")) {
        setDataSource(uri.getPath());
        return;
    }

    AssetFileDescriptor fd = null;
    try {
        ContentResolver resolver = context.getContentResolver();
        try {
            fd = resolver.openAssetFileDescriptor(uri, "r");
        } catch(FileNotFoundException e) {
            throw new IllegalArgumentException();
        }
        if (fd == null) {
            throw new IllegalArgumentException();
        }
        FileDescriptor descriptor = fd.getFileDescriptor();
        if (!descriptor.valid()) {
            throw new IllegalArgumentException();
        }
        // Note: using getDeclaredLength so that our behavior is the same
        // as previous versions when the content provider is returning
        // a full file.
        if (fd.getDeclaredLength() < 0) {
            setDataSource(descriptor);
        } else {
            setDataSource(descriptor, fd.getStartOffset(), fd.getDeclaredLength());
        }
        return;
    } catch (SecurityException ex) {
    } finally {
        try {
            if (fd != null) {
                fd.close();
            }
        } catch(IOException ioEx) {
        }
    }
    setDataSource(uri.toString(), null, null);
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:52,代碼來源:AvosMediaMetadataRetriever.java


注:本文中的android.content.ContentResolver.openAssetFileDescriptor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。