以下是我拍照的代码
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String name = imageFileName;
File file = new File(path, name);
Toast.makeText(getBaseContext(), file.toString(), Toast.LENGTH_LONG).show();
outputFileUri = Uri.fromFile(file);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
static final int REQUEST_IMAGE_CAPTURE = 1;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
this.imageView = (ImageView)this.findViewById(R.id.mImageView);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
这样可以拍照并在图像视图中放置缩略图
问题是它将图片保存在SD卡上的DCIM卡中时应将其保存在图片文件夹中,文件名为“Imagefilename”
toast我已将完整路径报告为
storage / emulated / 0 / Pictures / filename.jpg但是图片没有保存在那里
我在清单
中设置了读写权限任何我出错的想法
标记
答案 0 :(得分:0)
你需要这个:
cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT,outputFileUri );
在调用startActivityForResult之前..所以复制上面的代码:
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String name = imageFileName;
File file = new File(path, name);
Toast.makeText(getBaseContext(), file.toString(), Toast.LENGTH_LONG).show();
outputFileUri = Uri.fromFile(file);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT,outputFileUri );// add this
startActivityForResult(cameraIntent, CAMERA_REQUEST);