一:setDestinationInExternalPublicDir(“Trinea”, “MeiLiShuo.apk”);表示設置下載地址為sd卡的Trinea文件夾,文件名為MeiLiShuo.apk。
設置下載路徑接口為setDestinationUri,setDestinationInExternalFilesDir,setDestinationToSystemCache。其中setDestinationToSystemCache僅限系統app使用。
二:DownloadManager下載到內置目錄用這個setDestinationInExternalFilesDir(Context,null,filename)
SD卡根目錄下創建文件夾
1 /** 2 * 取得程式指定SDCard文件下載目錄 3 * 內置sdCard 4 * APP公用目錄 5 */ 6 public static String getCommonPath() { 7 //有sd卡 8 if (Environment.MEDIA_MOUNTED.equals(Environment 9 .getExternalStorageState())) { 10 // 創建一個文件夾對象,賦值為外部存儲器的目錄 11 File sdcardDir = Environment.getExternalStorageDirectory(); 12 // 得到一個路徑,內容是sdcard的文件夾路徑和名字 13 String path = sdcardDir.getPath() + "/" + "test"; 14 File path1 = new File(path); 15 if (!path1.exists()) 16 // 若不存在,創建目錄,可以在應用啟動的時候創建 17 path1.mkdirs(); 18 19 return path; 20 } else{ 21 //無SD卡 22 return ""; 23 } 24 25 }