如何使用DownloadManager通过url将文件下载到exSdCard?

时间:2013-12-03 11:56:36

标签: android url download

在此代码之后下载到sdCard,但我需要下载到exSdCard 我已尝试用

做到这一点
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, title+".flv");

但不起作用......它会下载到内部存储器

我也试过setDestinationInExternalFilesDir (context,Environment.DIRECTORY_DOWNLOADS, title+".flv"); 但它下载到内部存储器 Android / data / com.example.app / files / Download 文件夹

三星设备中的

:sdcard - 它是内部的 exSdCard它是http://content.answcdn.com/main/content/img/CDE/_COMPSD.JPG

 public void file_download(String uRl,String title) { 
File direct = new File(Environment.getExternalStorageDirectory() 
+ "/Download/Videos"); 

if (!direct.exists()) { 
direct.mkdirs(); 
} 

DownloadManager mgr = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE); 

Uri downloadUri = Uri.parse(uRl); 
DownloadManager.Request request = new DownloadManager.Request( 
downloadUri); 

request .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI|DownloadManager.Request.NETWORK_MOBILE) 
.setAllowedOverRoaming(false).setTitle(title) 
.setDescription("/Download/Videos/"+title) 
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, title+".flv"); 

mgr.enqueue(request); 

} 

1 个答案:

答案 0 :(得分:0)

getExternalStorageDirectory用于返回设备环境中设置为“外部存储”的内容。 它不是可移动媒体。而不是你只是尝试阅读isExternalStorageRemovable()以检查它是否可移动,并getExternalStorageState()来检查状态。有关详细信息http://developer.android.com/reference/android/os/Environment.html