【发布时间】:2019-07-16 20:07:43
【问题描述】:
您好,我在直接从相机上传图片时遇到问题。错误是:
/mnt/sdcard/Phoenix/default: open failed: ENOENT (No such file or directory)
我尝试了许多其他方法,但我面临同样的问题,即没有这样的文件或目录。 我的代码如下:
if (options[item].equals("Take Photo")) {
dialog.dismiss();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, PICK_IMAGE_CAMERA);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
inputStreamImg = null;
if (requestCode == PICK_IMAGE_CAMERA) {
try {
File f = new File(Environment.getExternalStorageDirectory().toString());
for (File temp : f.listFiles()) {
if (temp.getName().equals("temp.jpg")) {
f = temp;
break;
}
}
try {
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapPrescribedMed = BitmapFactory.decodeFile(f.getAbsolutePath(), bitmapOptions);
imgPrescribedMedicinePath = android.os.Environment
.getExternalStorageDirectory()
+ File.separator
+ "Phoenix" + File.separator + "default";
f.delete();
OutputStream outFile = null;
File file = new File(imgPrescribedMedicinePath, String.valueOf(System.currentTimeMillis()) + ".jpg");
try {
outFile = new FileOutputStream(file);
bitmapPrescribedMed.compress(Bitmap.CompressFormat.JPEG, 85, outFile);
outFile.flush();
outFile.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
有人可以帮帮我吗?
【问题讨论】:
-
你有存储访问权限吗?
-
检查默认文件夹是否存在,并验证您从哪里获取要上传的图像文件的路径
-
请指定测试设备和相应设备的Android API级别。
-
@Ashishsingh 是的,我已获得存储权限
-
@iCantC 我正在使用的设备的 api 级别是 17