Android Question Open failed: EACCES (Permission denied)

T201016

Active Member
Licensed User
Longtime User
Hi,
I'm working on resources located in the folder: android/data.
System: Android 12.
In the Manifest editor I added:

AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)

AddPermission(android.permission.MANAGE_EXTERNAL_STORAGE)
SetApplicationAttribute(android:requestLegacyExternalStorage, true)

and I can't read the contents of the selected file. Instead of this
I have an error message on the line:
What am I doing wrong?


Example:
        'The ExternalFile returned from ListFiles cannot be used directly.
        'We need to first call FindFile.
        f = Storage.FindFile(GetCurrentFolder, f.Name)
        If f.IsFolder Then
            EnterFolder(f)
        Else If IsFileINI(f.Name) Then
            Try
                Private outputstream As OutputStream = File.OpenOutput(File.DirInternal,"temp.ini",True)
                Private inputstreams As InputStream  = Storage.OpenInputStream(f)     '---> ERROR: (FileNotFoundException) java.io.FileNotFoundException:
                                                                                    'open failed: EACCES (Permission denied).

                ' Save file
                Wait for (File.Copy2Async(inputstreams, outputstream)) Complete (isCopy As Boolean)
                If inputstreams.IsInitialized Then inputstreams.Close
                If outputstream.IsInitialized Then outputstream.Close
               
                ...
        End if
       
'Open an input stream that reads from the file.
Public Sub OpenInputStream(EF As ExternalFile) As InputStream
    Return ctxt.RunMethodJO("getContentResolver", Null).RunMethod("openInputStream", Array(EF.Native.RunMethod("getUri", Null)))
End Sub
 

agraham

Expert
Licensed User
Longtime User
Without seeing more of your code you seem to be jumbling up different ways of file access. If you are requesting and receiving MANAGE_EXTERNAL_STORAGE you don't need requestLegacyExternalStorage. With MANAGE_EXTERNAL_STORAGE you use the normal file access mechanisms to access the file store except Android/data and Android/obb

If you read the first post there you will find this
EDIT: If for some reason you need to access folders under Android/data or Android/obb there is a loophole in post #35 here. Note that this is probably not intentional on Googles part and may be may closed in the futire. If your File Explorer on your device can access these folders this is how it is doing it.
Post #35 in this thread has an example of accessing Android/data using ExternalStorage.
 
Upvote 0

T201016

Active Member
Licensed User
Longtime User
Without seeing more of your code you seem to be jumbling up different ways of file access. If you are requesting and receiving MANAGE_EXTERNAL_STORAGE you don't need requestLegacyExternalStorage. With MANAGE_EXTERNAL_STORAGE you use the normal file access mechanisms to access the file store except Android/data and Android/obb

If you read the first post there you will find this

Post #35 in this thread has an example of accessing Android/data using ExternalStorage.
I've read these posts before, I understand that now and in the future it is no longer possible to save files in the Android/data directories from the Android level?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
it is no longer possible to save files in the Android/data directories from the Android level?
You can for now using the example I posted in post #35 of the thread I linked to above. There is no guarantee that this, probably unintended loophole, won't be closed in the future.
 
Upvote 0
Top