0

我正在通过相机应用程序捕获图像并希望存储在特定文件夹中,但图像未存储在文件夹中,这是我的代码:

File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/" + "my_data");
                try {
                    if (!dir.exists())
                        if (dir.mkdir()) {
                            System.out.println("Directory created");
                            Toast.makeText(Add.this, "created dir",
                                    Toast.LENGTH_LONG).show();
                        }

                    image_path = Environment.getExternalStorageDirectory().getPath() + "/my_data/" + aa + "_image.jpg";
                    File file = new File(dir,image_path);

                    uriImage = Uri.fromFile(file);
                    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, uriImage);
                    startActivityForResult(intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 
4

1 回答 1

0

编辑

这应该有效,如果没有,请发布 logcat 输出。

     String folderPath = Environment.getExternalStorageDirectory().toString()
                        + java.io.File.separator + "my_data"
                        );
     File dir = new File(folderPath);
     if(!dir.exists){
        dir.mkdirs();
       }

    imagePath = folderPath+java.io.File.separator+aa+"_image.jpg";
于 2013-05-27T14:32:02.507 回答