ivehement / saf

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.
https://pub.dev/packages/saf
MIT License
17 stars 19 forks source link

PathAccessException when reading non-media files on Android 13 after getDirectoryPermission #24

Open tomekit opened 1 year ago

tomekit commented 1 year ago

I am selecting: "Testupload" folder for upload which contains two files, image.jpg and contacts.vcf.

I can read image OK, but when I try to read contents of: contacts.vcf I get the PathAccessException. I can get the file length for contacts.vcf using: file.lengthSync();, but I can't get the contents.

Saf saf = Saf("~");
bool? isGranted = await saf.getDirectoryPermission(grantWritePermission: true, isDynamic: true);
final filePaths = await saf.getFilesPath();

filePaths?.forEach((absolutePath) {
  final file = File(absolutePath);
  final test = file.readAsBytesSync(); // PathAccessException: Cannot open file, path = '/storage/emulated/0/Testupload/contacts.vcf' (OS Error: Permission denied, errno = 13)
}

I am using:
• Flutter version 3.10.0 on channel stable at /opt/flutter

I can reproduce it on Pixel 5 API 33 emulator as well as on real device SM-M127F (Android 13). I haven't tested it on older devices.

Any idea why I can't read non-media files?

MridulVij commented 1 year ago

Bro i also facing same issue i have granted the file access inside Android/data/com.example.app but im unable to transfer the file inside it in Android 12 ? can you please help me out it is perfectly working in Android 10 but the same app i open in Android 12 device it will show the Path Access Exception error? Can you please help me out? how can i resolve this issue?

tomekit commented 1 year ago

I think that with SAF one is not supposed to read file "directly" but needs to operate on Content URI's, I've added specific method to add content URI in my fork: https://github.com/ivehement/saf/compare/master...tomekit:saf:master

MridulVij commented 1 year ago

Hi Sir can we Connect on linkedin? to talk i have little query about files transferring between Android/data in Android 11,12,13 devices by using this package im able to access the particular path of folder that i have entered to access but im unable to transfer file in it. again showing pathaccessexeception in android 12 device

so can we connect on Linkedin? My ID - https://www.linkedin.com/in/mridul-vij-31969b160/

brandon-watkins-avcrm commented 3 months ago

Any updates on this one? I am also getting this problem on Android 13 :(