一: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 }