alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
308 stars 22 forks source link

How to ask permission for specific folder #43

Closed EndLess728 closed 2 years ago

EndLess728 commented 2 years ago

I installed one app from playstore and it downloads the whatsapp stories (basically fetches the . statuses folder from internal storage)

When I installed that app, It directly opened WhatsApp/. statuses folder to ask permission for that specific folder

As per new android 11 policy now no app can get third party folder access it need the access from file manager.

I want to ask if there is any method I can ask permission for specific folder. Like WhatsApp or any other folder ?

alpha0010 commented 2 years ago

It depends on the purpose of access and what control you have over the other app you want files from.

It sounds like you want to see "App-specific files" https://developer.android.com/training/data-storage , which are stated as not accessible to other apps. To make them usable, the first choice would be to add a content provider to the other app. Of course, that is not possible if you do not own the other app. In that case, your only option is to try using the MANAGE_EXTERNAL_STORAGE permission (very broad permission, so could get your app rejected from review if it does not have a good justification), but even that might not be enough.

Unfortunately, I do not believe there is any other way (though if you find one, let me know).

EndLess728 commented 2 years ago

I know it can be possible with MANAGE_EXTERNAL_STORAGE permission but It is used to access to all the files of storage.

Kindly look at the app I have given link bellow, I decompiled this and checked AndroidMenifest.xml and he did not used this permission. Also I checked it's target sdk and it was 30.

I think he used SAF in some tricky way he directly navigate users to whatsapp/.statues folder (without manualy choosing folders from internal storage)

Note : The below link is not for promotion. It is to clearify the actual working which i need. https://play.google.com/store/apps/details?id=com.downlood.sav.whmedia

EndLess728 commented 2 years ago

Finally !! I have found a way to directly ask permission to any specific folder (without manually going into that folder)

I am using expo file system and I used SAF to get the specific folder URI and then asked permission for that specific folder.

Mudassirraza912 commented 1 year ago

@EndLess728 can you guide me how you solved this?

`// Requests permissions for external directory const permissions = await StorageAccessFramework.requestDirectoryPermissionsAsync( 'content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses', );

if (permissions.granted) {
  // Gets SAF URI from response
  const uri = permissions.directoryUri;

  // Gets all files inside of selected directory
  const files = await StorageAccessFramework.readDirectoryAsync(uri);
  console.log(`Files inside ${uri}:\n\n${JSON.stringify(files)}`);
}`

I tried this code but it's not working its open the root directory instead of given directory