我正在使用以下代码使用原生相机拍照:
private File mImageFile;
private String mTempImagePath;
public static Uri imageUri;
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d("fototemp", "No SDCARD");
} else {
mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"testFolder", "Pic"+System.currentTimeMillis()+".jpg");
imageUri = Uri.fromFile(mImageFile);
DataClass dc = (DataClass) getApplicationContext();
File tempFile = new File(Environment.getExternalStorageDirectory()+File.separator+"testFolder");
Uri tempUri = Uri.fromFile(tempFile);
dc.setString(DataClass.IMAGE_PATH, tempUri.toString());
Log.d("fototemp", "ImagePath: " + tempUri.toString());
mTempImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, 0);
}
}
我在imageFromCamera()方法中打印出的ImagePath是:4file:/// file%3A / mnt / sdcard / testFolder
现在,当我尝试使用managedQuery访问这些照片时,我得到了一个不同的目录。 MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI.toString()提供内容:// media / external / images / thumbnails
这两条路径有什么区别?如何让managedQuery转到testFolder地图查找图片?
编辑: 我正在尝试连接:
Uri phoneUriII = Uri.parse(Environment.getExternalStorageDirectory()+File.separator+"testFolder");
imagecursor = managedQuery(phoneUriII, img, null,null, MediaStore.Images.Thumbnails.IMAGE_ID + "");
但此代码崩溃
答案 0 :(得分:0)
抱歉,不太了解你的问题。
只需将此作为URI路径发送。
Environment.getExternalStorageDirectory()+文件分割符+ “testFolder”
另外 检查您是否有权写入SD卡。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
答案 1 :(得分:0)
我在几个项目中使用此功能,它工作正常。
/**
* Retrieves physical path to the image from content Uri
* @param contentUri
* @return
*/
private String getRealImagePathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}