如何为丢失质量的捕获图像创建单独的文件夹

时间:2018-05-04 05:00:18

标签: android android-camera

您好我正在尝试使用以下代码为捕获的图像创建单独的文件夹,但我得到异常 android.os.FileUriExposedException:file:/// storage / emulated /0/myFolder/photo_20180504_102426.png通过ClipData.Item.getUri()

暴露在app之外

mi-stack可以做些什么来纠正我的代码

String folder_main = "myFolder";
            File f = new File(Environment.getExternalStorageDirectory(), folder_main);
            if (!f.exists()) {
                f.mkdirs();
            }
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File file = new File(Environment.getExternalStorageDirectory(), "/myFolder" + "/photo_" + timeStamp + ".png");
            imageUri = Uri.fromFile(file);

            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
            startActivityForResult(intent, Constants.CAMERA_REQUEST_CODE);

 private void onCaptureImageResult(Intent data) {

        try {

            Bitmap thumbnail = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
            CircleImageView circleImageView = findViewById(formFields.get(imagePosition).getId());
            circleImageView.setImageBitmap(thumbnail);
}

1 个答案:

答案 0 :(得分:1)

把它放在你的oncreate()

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());