0

I am working on a book application where users would need to first download a book as pdf before reading it. I don't want any user to be able to access any pdf after download except from the application. I am using Download Manager which worked well. But am having two challenges. First, the pdf don't get downloaded into the specified folder and the file is accessible. How do effect this?

 private void downloadFile() {
        if(Build.VERSION.SDK_INT >= 23){
            if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                Uri uri = Uri.parse(document);
                String extension = document.substring(document.lastIndexOf("."));
                mDownloadBtn.setText("DOWNLOADING");
                DownloadManager.Request request = new DownloadManager.Request(uri);
                request.setTitle(title);
                request.setVisibleInDownloadsUi(false);
                request.setDescription("NewFolder");
                request.setDestinationInExternalFilesDir(this, DIRECTORY_DOWNLOADS, File.separator + "NewFolder" + File.separator + title + extension);
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                reference = downloadManager.enqueue(request);

            } else{
                ActivityCompat.requestPermissions(AddedLibraryActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
            }
        }
        //we can use this reference to track the download state of our file.
    }
bennycodest
  • 379
  • 1
  • 5
  • 14

1 Answers1

0

AFAIK, DownloadManager only downloads to external storage. To download to internal storage, you can download the PDF yourself, using your favorite HTTP client API (e.g., OkHttp).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491