6

我的应用程序面临两个问题。

1-我正在使用 AndroidDownloadManager下载在线文件,但它Download通过使用将所有文件下载到系统目录说目录

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, "fileName");

现在我想将文件下载到我自己的目录中,比如“新建文件夹”。怎么可能实现。请在这方面帮助我,我将不胜感激。

2-如何检查SD卡是否可用?

4

2 回答 2

9

使用这种方式:这里 Dhaval_files 是我的文件夹名称

public void file_download(String uRl) {
        File direct = new File(Environment.getExternalStorageDirectory()
                + "/dhaval_files");

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

        DownloadManager mgr = (DownloadManager) this.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("Demo")
                .setDescription("Something useful. No, really.")
                .setDestinationInExternalPublicDir("/dhaval_files", "test.jpg");

        mgr.enqueue(request);

    }
于 2013-04-30T07:22:23.150 回答
3

下载管理器

1)

Uri downloadUri = Uri.parse(DOWNLOAD_FILE);
            DownloadManager.Request request = new DownloadManager.Request(downloadUri);
            request.setDescription("Downloading a file");
            long id =  downloadManager.enqueue(request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI |DownloadManager.Request.NETWORK_MOBILE)
                    .setAllowedOverRoaming(false)
                    .setTitle("File Downloading...")
                    .setDescription("Image File Download")
                    .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "cm.png"));

2)

Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

if(isSDPresent)
{
  // yes download code
}
else
{
 // No sdcard 
}
于 2013-04-30T07:11:04.387 回答