Android Question Android 13 and Android 14 PERMISSION_WRITE_EXTERNAL_STORAGE problem

hung

Active Member
Licensed User
Longtime User
This is the code working for years up to Android 12 since Android 8.

B4X:
    gRp.CheckAndRequest(gRp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        Dim outs As OutputStream = File.OpenOutput(gRp.GetSafeDirDefaultExternal("") , gs_filename, False)
    ...
        outs.Close
    Else
        ToastMessageShow("Failed to create file", False)
    End If

manifest is like this
B4X:
AddManifestText(<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="30" />
)

I recall it worked in Android 13 about a month ago. But now failed to get permission then prompt "Failed to create file" all the time.

I am not using Google Store but put apk in private server for download.

I recently compiled min sdk 21 and target sdk 35. Now recompiled as min sdk 21 and target sdk 33. Neither working.
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
Upvote 0

hung

Active Member
Licensed User
Longtime User
Thanks. Tried your example which works but failed when I use GetSafeDirDefaultExternal.

I further debug then found the following

B4X:
 gRp.CheckAndRequest(gRp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
    ...

The problem is CheckAndRequest failed to return permissionResult (in Android 13 and 14, but no issue in Android 9-12), hence timeout then prompt "failed" message.

If I comment the CheckAndRequest and Wait For Acitivity_PermissionResult, and and comment "If Result then", I can create file in GetSafeDirDefaultExternal folder. i.e. my app has got access to create new files.

Then question is why CheckAndRequest(gRp.PERMISSION_WRITE_EXTERNAL_STORAGE) failed?
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
You are using
B4X:
gRp.GetSafeDirDefaultExternal("")
As far as I know this does not require any permission.
So the request for
B4X:
PERMISSION_WRITE_EXTERNAL_STORAGE
it's not needed, I think.
 
Upvote 0

hung

Active Member
Licensed User
Longtime User
You are using
B4X:
gRp.GetSafeDirDefaultExternal("")
As far as I know this does not require any permission.
So the request for
B4X:
PERMISSION_WRITE_EXTERNAL_STORAGE
it's not needed, I think.
Thank you Sagenut. This works (I thought it was workaround :D ).

Also notice there was new b4x deployed by Erel. Download and use new ide to compile, solved other part of my problems. i.e. next time when Erel release a version, should download and recompile and test app asap.
 
Upvote 0
Top