0

There are multiple such questions out there, however, they are not able to solve the problem.

build.gradle

  • compileSdkVersion - 29
  • buildToolsVersion - 29.0.3
  • midSdkVersion - 26
  • targetSdkVersion - 29
  • Android Studio - 3.6
  • Testing Device OS - Android Q (10)

Android Manifest.xml

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />

Activity.java

String filepath = '/path/to/file';
filepath.exists() // true
filepath.canRead() // false
filepath.canWrite() // false

ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED // true
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED // true

The MainActivity is not able to read the file despite the fact that the file exists and the relevant permissions have been granted. Is there any other solution to this problem?

ranka47
  • 995
  • 8
  • 25
  • What version of Android are you testing on? – CommonsWare Feb 25 '20 at 21:59
  • Does this help? https://stackoverflow.com/questions/33030933/android-6-0-open-failed-eacces-permission-denied?rq=1 – Tom Feb 25 '20 at 22:00
  • updated the question with android version details. – ranka47 Feb 25 '20 at 22:02
  • 1
    You have no access to arbitrary locations on external and removable storage on Android 10+. The `android:requestLegacyExternalStorage="true"` workaround will not work on Android 11+. So, either change where this file is located, use the Storage Access Framework, or use `MediaStore`. – CommonsWare Feb 25 '20 at 22:04
  • @Tom thanks for pointing it out. But that doesn't answer the question. – ranka47 Feb 25 '20 at 22:13
  • @CommonsWare that answers it. Thanks. – ranka47 Feb 25 '20 at 22:13

0 Answers0