2012-04-12 98 views
1

我试图告诉我的应用程序让一些已经下载的图像出现在我手机的图库中。 图片很好下载并显示在我的应用程序中,他们没有扩展名,他们的名字只有一个md5。在我的手机图库中显示下载的图像

这里是如何我试图这样做:

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

在这条线的应用程序崩溃:

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

此消息:

java.io. FileNotFoundException:/mnt/sdcard/data/com.example.app/images:打开失败:EISDIR(是一个目录)

有没有人知道它是什么?

回答

0

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

相关问题