本文整理汇总了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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}