-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReadPermission False #106
Comments
If you have write permission then automatically you have read permission, you don't need both. Let me know if it answers your question! Thanks. |
I came here with the same question, because it seems that although I do have write permission and can create files in the folder I selected, I can't read files. I'm using the sample app, with the only changes being I specified 0.5.0 in
Note the URI string I'm using there is the one I got from output of the sample app after I select the folder (with the file name appended). When I run the app, select the folder in question and grant permissions etc, the sample app shows that I have write permissions for that folder, but not read permissions, as seen here: If I choose the Create Sample File action, it creates Sample Files.txt in the selected folder (or variants with the number at the end if that already exists).
I'm not that experienced with Flutter or Android, and I'm definitely brand new to SAF etc, so I may be missing something, but it looks to me as though I do indeed have write access, but not read access. The folder in question is owned by someone else's app, so maybe that's the problem? But surely if I can write to that folder I should be able to read the files I've written there. Or is read permission only at the folder level, ie to be able to see the files in that folder, and I need to do something extra to actually read a file? Thanks. |
const String stringUri = 'content://com.android.externalstorage.documents/tree/primary:Sigames/Documents/Sports Interactive/Football Manager 2022 Mobile/normal/games/Sample File.txt'; SAF needs to know the tree and the document, you're passing only the tree. Take a look at this fn:
It does what you want: read the file tree within a folder. Let me know if it helps. |
Finally circling back to this. Thanks for the eg, but I still didn't really get the logic of it! I was trying to open a single file rather than read a file tree and just couldn't work out how to do it. But then I noticed that there'd been a couple of new versions and that the example app has been updated, so I gave that a spin and it now has an Open document button/link. That does exactly what I want - although I'd love to be able to get access to all files in a folder rather than having to get the user to select them 1 by 1. Anyway, I managed to edit the example to open a hex file and process the contents etc, so I've proved the concept to myself and gotten over the hurdle I was stuck at. Thanks so much for your help and the work on this library. |
Well maybe I spoke too soon! I can get the user to give permission to access a file, then read it, but as soon as the file changes, the permission is gone again. Is that a limitation of the SAF model? I need to be able to get permission to access a file once and then be able to access it through continuous changes. The context is I have an app that opens a save file from a third party game and shows the user extra information not available in the game itself. The user will be saving the save file constantly, but will then switch to my app and refresh it to see the changes. If I have to ask them for permission to open the file every time, that's going to drive them crazy... I realise that this may very well be outside the scope of this library, but if you have any pointers (even it if is just confirming there's no way to do what I want through SAF), that would be a great help. Thanks |
I think this is supported with Also, can you provide your Android version? Side-note: this use-case needs the library v0.7.0, since this release launched the |
That's the purpose of Edit: managed to use |
@alexrintt Thanks for your quick response.
This is happening when running debug on a Samsung S20+ with Android 12.
I've investigated this a little further now and have some more details. This is using the example app from the latest .zip file download. My only changes were to specify 0.7.0 in pubspec.yaml and then a few changes to
Here's a screenshot of the changes: Apart from that the code is exactly the same as the demo. I then used the New allowed files link in the app and selected the file I wanted to open, resulting in this: When I click Open document, it reads the file and displays the text seen in the following screenshot (date, name, teams) - I'll be converting the entire file content to HEX, but it's quite useful that it's displaying the string value here: So far so good. Even better, if I use a HEX editor to change the contents of the file and save it and then click Open document again, the changes appear! At one point during my testing, I deleted the file from the phone entirely, then copied a modified version back and it had no problem opening it. However, if I go back to the third party game and use the save game function in there and then click Open document again, the app crashes and I see these in the debug console:
When I restart the app (via VS Code Run and Debug), the permission for that file no longer appears (it is normally retained when disconnecting and reconnecting/re-running the app). I can of course open New allowed files and select the file again and it will get the contents of the modified file, but that's what I'm hoping to avoid. So it looks like I DO get persistent permissions to the file that last beyond file changes in most cases, but NOT when the original app that owns that file changes it. At that point permissions are ... revoked? Maybe it's something they do with saving the file? Maybe it's because that app own's the file? I have no idea about what could be causing that and I appreciate you won't be able to replicate it without having the game, so not sure where to from here... With the Thanks again for your help with this, I really appreciate it. |
Can you show the full error stack trace? I wanna see the path of the native function calls, but you uploaded only few lines. You can create a gist and then paste the link here if you want to avoid spamming 300 lines of log. I could not get to reproduce this error in any type of environment, even between several application. I've tested already with Android 8, 10, 12 and 13. Would be helpful if you share your game (where I can download). If you wanna share the game name in private, you can always send me a message on telegram or at my email [email protected]. |
Here is the full content of the debug console covering launch app in debug mode, select file, open file successfully, switch to third party game and open / resave file there, switch back to app and choose Open file again: I'll email you some details about the third-party game (just to be clear, I'm not the author of the game, I'm making a tool that works with someone else's game, if that makes any difference). Thanks again for your help. |
Read Permission is false even after openDocumentTree
but write permission is true
The text was updated successfully, but these errors were encountered: