0

I am using an url to download and read bytes of data using InputStream, the data thus fetched I am writing using a FileOutputStream in form of a pdf. Then I am using Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();

to write the file in the downloads folder.

The file gets downloaded in the Download folder, and I can access it using FileManager, no issues in that. But the file does not appear in the Downloads app. So, I tried by using DownloadManager object

mManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);

and once the download has happened, I am using

mManager.addCompletedDownload(fileName, "Hello", true, "application/pdf", "nn",bufferLength,false);

from sources

addCompletedDownload method

Now, my first query,

  1. I am not quite being able to understand what I must mention for String path

  2. Using this line of code, I am getting an SecurityException which says securityexception invalid value for visibility 2 android

Any help is highly appreciated.

akash89
  • 881
  • 3
  • 12
  • 31
  • if you want to download a file to the public Downloads directory, it may be easier to use **DownloadManager.enqueue()** – Alex Cohn Jun 21 '20 at 08:52

2 Answers2

3

In case you don't want to show the download notification, like in your code, you should add the permission for it in the app manifest file:

<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>
Shlomi
  • 343
  • 5
  • 23
0

SecurityExceptions usualy rised when you dont provide needed permissions.Also maybe this will be helpfull : http://technofaq.org/posts/2014/04/fixing-external-sd-card-write-issue-on-android-kitkat/

Void
  • 1,129
  • 1
  • 8
  • 21
  • If you are referring to android.permission.READ_EXTERNAL_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE, these are already taken care of, but still I don't see any improvement. – akash89 Mar 02 '16 at 13:50
  • Latest android versions have some permissions bugs see this link : http://stackoverflow.com/questions/17360924/securityexception-permission-denied-missing-internet-permission – Void Mar 02 '16 at 14:00
  • I hope you already know that you need to add this : – Void Mar 02 '16 at 14:06