0

Im trying to read a json file from an external storage without sucess. Im getting the error:

Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord{bfaa1d6 26301:com.plm.valdecillasurdemo/u0a284} (pid=26301, uid=10284) requires that you obtain access using ACTION_OPEN_DOCUMENT or related API
  1. My manifest.xml file is OK
  2. I am checking in runtime for READ_EXTERNAL_STORAGE permission and only read the file when the permission is granted
  3. When I try read the file I getting the related error.

In a second approach I started an ACTION_OPEN_DOCUMENT Intent.

A system dialog ask me for picking a file and all is fine. I read the file correctly however I dont want be asked for a Uri. My Uri is hardcoded.

I know must be easy the solution but this problem is drives me crazy...How can I resolve this?

Thanks in advance.

Pablo Lanza
  • 338
  • 1
  • 8
  • Have you tried the [solutions proposed here](https://stackoverflow.com/questions/32431723/read-external-storage-permission-for-android/32617585) ? – Anis Brachemi Oct 28 '20 at 23:30

1 Answers1

1

My Uri is hardcoded

That is not possible. You do not have rights to such a document, even if the Uri is valid (which it won't be, since the DocumentsProvider did not do any work on its side to grant it). Beyond that, the user may not have a document at the location that you hard-coded.

How can I resolve this?

Use ACTION_OPEN_DOCUMENT and allow the user to choose the document to remove.

Or, use filesystem locations that you can read and write across OS versions, mostly those defined on Context: getFilesDir(), getCacheDir(), getExternalFilesDir(), getExternalCacheDir(), etc. In this case, you will not need to work with Uri values.

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