標籤:
一: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 }
android setDestinationInExternalPublicDir 下載到SD卡根目錄