2012-04-12 55 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」的文件夾。

相關問題