RonRadtke / react-native-blob-util

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
758 stars 130 forks source link

can't read my files from the legacy path on android 10 #312

Closed lucas-samuel01 closed 8 months ago

lucas-samuel01 commented 11 months ago

Hi everyone !

I'm having some truble with my app for my android 10 users, the problem is that I can't read my files from the legacy path only in the andorid 10 devices. They already had images downloaded and I need to access them, anyone knows how can I do that ? I also can write files normally but I can't read any of them, and I have all the permissions. But everytime that I try to read the files I get the following message: "Attempt to get length of null array"

Permissions in my Android manifest

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

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

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="29" />

version of installed library: 0.19.2 react-native version: 0.72.4

My gradle ext: buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 ndkVersion = "23.1.7779620"

  function readPNGByDir() {
    try {
      RNFetchBlob.fs.ls(`${RNFetchBlob.fs.dirs.LegacyDownloadDir}/PNG`).then(async (files) => {
        for (const file of files) {
          console.log("my files", file)
        }
      })
    } catch (e) {
      console.log('read png error', e)
    }
  }
RonRadtke commented 11 months ago

If you're still targeting android 10 try to request the kegacy storage

Which value do you get for the path?

https://medium.com/mindful-engineering/scoped-storage-in-android-d52460630d6a

vlack-coder commented 10 months ago

@RonRadtke I get the path correctly but when I try to write to the path, I get permission denied error and I've tried the suggested flag in the article you shared. My Android version is 10 and API is 29 Thanks android:requestLegacyExternalStorage="true"

vlack-coder commented 10 months ago

@RonRadtke no worries, I've solved it so instead of using the LegacyDownloadDir API, I used dirs.DownloadDir and copied to the media store.. Thanks