如果你能以正确的方式指出我,请提前致谢!
MainActivity中的:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
在MyFragment中:
foto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/DCIM/Myapp/testPhoto.jpg")) );
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/DCIM/Myapp/testPhoto.jpg"));
startActivityForResult(cameraIntent,CAMERA_REQUEST);
}
和同一片段中的onActivityResult:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
System.out.println("Called");
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap bitmap=null;
try{
bitmap = BitmapFactory.decodeStream(getActivity().getContentResolver().openInputStream(imageUri));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
答案 0 :(得分:0)
花了很多时间才找到解决方案......问题只是我没有检查目录是否存在保存照片...实际上我为了测试目的而更改目录而忘记更改它生产。如果它不存在则不会报告错误但您无法保存当前加载的照片!