2013-11-15 29 views
0

我會下載與DownloadManager在一個特定的目錄中的文件。在我的應用程序開始時,我創建了(如果不存在)的文件夾:無法給一個DownloadManager的路徑

if (storageState.equals(Environment.MEDIA_MOUNTED)) { 
     externalStorageWriteable = true; 
     directory_path = Environment.getExternalStorageDirectory() 
       + "/" + context.getResources().getString(R.string.app_name); 
     directory = new File(directory_path); 
     if (!directory.exists()) { 
      directory.mkdirs(); 
     } 
    } 

,如果我有一個文件管理器檢查,文件夾,它可以在/ SD卡/ FOLDERNAME,但如果我在logcat的目錄路徑可變印刷,我獲得

/storage/emulated/0/folderName 

我試圖通過傳遞目標文件夾一樣

Uri destination = Uri.fromFile(new File(directory_path)); 
request.setDestinationUri(destination); 
//request is of type DownloadManager.Request 

下載文件,但是當我檢查其中file它的存儲,我的文件夾是空的,下載的文件存儲在側/ sdcard /下載

有人能告訴我爲什麼以及如何解決這個問題?

回答

0

添加的ToString()

Environment.getExternalStorageDirectory().toString() 
+0

它不工作過。 – giozh