简体   繁体   中英

Cannot download file using ThinDownloadManager library in Android

I am developing my first Android project. In my project, I need to download mp3 file. So I am using ThinDownloadManager library to download mp3 file easily. But it is not downloading file.

I installed library using grandle

compile 'com.mani:ThinDownloadManager:1.2.1'

This is my download function

private void downloadPodcast(int id)
    {
        String url = context.getResources().getString(R.string.api_endpoint)+"?id="+String.valueOf(id);

        Uri downloadUri = Uri.parse(url);
        Uri destinationUri = Uri.parse(context.getExternalCacheDir().toString()+"/test.mp3");
        DownloadRequest downloadRequest =
                new DownloadRequest(downloadUri).setDestinationURI(destinationUri).setPriority(DownloadRequest.Priority.HIGH);
    }

It is not downloading anything. I access the URL directly, it is downloading. But when download using this code by button click event, it is not working. Why it is not working?

Hmm, u created download request, and think that is all? U need do some more to download:
Put this to Your class:

ThinDownloadManager downloadManager=new ThinDownloadManager();

Then in Your download function add:

downloadManager.add(downloadRequest);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM