我正在这样做:
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
final File storage = Environment.getExternalStorageDirectory();
final Uri uri = Uri.fromFile(new File(storage, System.currentTimeMillis() + ".jpg"));
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, id);
并处理得到那张照片,我这样做:
private String getLastImagePath() {
final String[] imageColumns = { MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA };
final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
final Cursor imageCursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns,
null, null, imageOrderBy);
if (imageCursor.moveToFirst()) {
final String fullPath = imageCursor.getString(imageCursor
.getColumnIndex(MediaStore.Images.Media.DATA));
return fullPath;
} else {
throw new RuntimeException();
}
}
但是,我不断收到这样的消息:
07-02 14:46:54.751: E/BitmapFactory(23119): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/IMG_20130702_144653.jpg: open failed: ENOENT (No such file or directory)
如果我检查图库,照片不在那里,所以我的猜测是 Intent 忽略了该MediaStore.EXTRA_OUTPUT
值。
有什么我可以做的不涉及编写我自己的相机解决方案吗?