如何通过使用Android的下载管理器,保存在SD卡上的文件? [英] How to save file on SD card by using download manger in Android?

查看:187
本文介绍了如何通过使用Android的下载管理器,保存在SD卡上的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面对我的应用程序拖的问题。

I am facing tow issues in my app.

我使用的是Android 下载管理器下载网上文件,但它下载到系统目录中的所有文件1说下载通过使用目录

1- I am using Android DownloadManager to download online files but it downloads all files to system directories say Download directory by using

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

现在我想将文件下载到我自己的目录说新建文件夹。这怎么可能实现。请帮我在这方面,我会非常感激。

Now I want to download the file to my own directory say "New Folder". How is it possible to implement. Please help me in this respect, I would be very thankful.

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

2- How can I check that whether SD card is available or not?

推荐答案

用这样的方式:在这里Dhaval_files是我的文件夹名称

use this way: Here Dhaval_files is my folder name

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);

    }

这篇关于如何通过使用Android的下载管理器,保存在SD卡上的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆