无法将图像存储在SD卡中的特定文件夹中

时间:2013-05-27 14:22:47

标签: android android-camera android-sdcard

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

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); 

1 个答案:

答案 0 :(得分: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";