1

I'm trying to tell my app to make some images which are already downloaded appear in the gallery of my phone. the images are well download and displayed in my app, they have no extension, their names are only a md5.

here is how i'm trying to do so:

public static void makePhotoAppearOnGallery(Activity activity, String md5) {
        final String extStorageDirectory = Environment
                .getExternalStorageDirectory().toString();
        final String festivalDirectory_path = extStorageDirectory
                + Constants.IMAGES_STORAGE_PATH;
        File imageOutputFile = new File(festivalDirectory_path, "/");
        if (imageOutputFile.exists() == false) {
            imageOutputFile.mkdirs();
        }
        File imageFile = new File(imageOutputFile, md5);
        Bitmap bm = decodeFile(imageFile.getAbsoluteFile());
        OutputStream outStream = null;
        try {
            outStream = new FileOutputStream(imageFile);
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        bm.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
        try {

            outStream.flush();
            outStream.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            MediaStore.Images.Media.insertImage(activity.getContentResolver(), festivalDirectory_path, festivalDirectory_path+"/"+md5, "myDownloadedPics");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        scanFile(imageFile,activity);


    }
     public static void scanFile(File downloadedFile, Context mContext){
         Uri contentUri = Uri.fromFile(downloadedFile);
         Intent mediaScanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
         mediaScanIntent.setData(contentUri);
         mContext.sendBroadcast(mediaScanIntent);
     }

the app crashes on this line:

MediaStore.Images.Media.insertImage(activity.getContentResolver(), festivalDirectory_path, festivalDirectory_path+"/"+md5, "myDownloadedPics");

with this message:

java.io.FileNotFoundException: /mnt/sdcard/data/com.example.app/images: open failed: EISDIR (Is a directory)

Does anyone know from what it comes?

4

1 回答 1

0

我有同样的问题。事实证明,当存在具有相同文件名的文件夹时会发生此错误。例如,我有一个名为“log.txt”的文件夹。

于 2012-07-13T14:34:34.000 回答