Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

downloading files using dropbox url android

I am trying to download files using dropbox url. I copied a code from Download a file with Android, and showing the progress in a ProgressDialog which uses DownloadManager class.

    public void downloadFromDropBoxUrl(View view) {
        //verfying if the downloadmanager is available first.
        if (isDownloadManagerAvailable(getApplication())) {
            String url = "https://www.dropbox.com/s/m4z5u9qstxdtbc3/AllExams22.pdf?dl=0";
            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
            request.setDescription("Some descrition");
            request.setTitle("Some title");
// in order for this if to run, you must use the android 3.2 to compile your app
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            }
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "my-map.pdf");

// get download service and enqueue file
            DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
            manager.enqueue(request);
        }
    }
    public static boolean isDownloadManagerAvailable(Context context) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
            return true;
        }
        return false;
    }

It is working on achiving direct files with urls but this time I am trying to do it with dropbox share links but its not working out. I don't want to connect to dropbox api. I think it is useless. Is there any way I can download files directly from the dropbox url?

like image 257
Ibrahim Shalhoub Avatar asked Nov 08 '15 13:11

Ibrahim Shalhoub


2 Answers

just replace

String url = "https://www.dropbox.com/s/m4z5u9qstxdtbc3/AllExams22.pdf?dl=0";

by:

String url = "https://dl.dropboxusercontent.com/s/m4z5u9qstxdtbc3/AllExams22.pdf";    

Then:

final DownloadTask downloadTask = new DownloadTask(YourActivity.this);
downloadTask.execute(url);
like image 138
Robust Avatar answered Oct 16 '22 23:10

Robust


Please see this link on how to download a shared file from Dropbox

https://blogs.dropbox.com/developers/2013/08/programmatically-download-content-from-share-links/

like image 24
OneCricketeer Avatar answered Oct 17 '22 01:10

OneCricketeer