Permission denied when creating a new file (Android 11)

37 views
Skip to first unread message

nordhal...@mixvibes.com

unread,
Aug 5, 2021, 5:25:37 PMAug 5
to android-ndk
Hi,
I'm quite confused with the way Storage Access Framework could work with Native code. 

After given the user the choice to select a folder using the intent action OPEN_DOCUMENT_TREE, I create my file using DocumentContracts.CreateDocument(...)

However, when I want to open this file in my native code, I have an error saying that I don't have the access to it. 
How is it possible ? I thought in Android 11, each file created is owned by the app. Is this different from the native code ? 

Thanks 

Alex Cohn

unread,
Aug 22, 2021, 12:34:30 PMAug 22
to android-ndk
You should use the file descriptor for document created in intent. Access by file name may go wrong.

BR,
Alex

nordhal...@mixvibes.com

unread,
Aug 25, 2021, 6:45:39 PMAug 25
to android-ndk
Hi Alex,
Thanks for the answer..
Unfortunately, at this point in our native code, we are unable to work with a file descriptor and get an inputStream for here. 
My workaround was to generate files within my app directories, and then moving these files using the DocumentContracts and the document tree URI.retrieved from OPEN_DOCUMENT_TREE intent. 

Best Regards,

Nordhal 
Reply all
Reply to author
Forward
0 new messages