Android Question How to access Android/data on Android 11?

Thu Ya

Member
Now I am trying to access Android/data folder on Android 11 for reading and writing.
But I can't even list the Android folder.

Some app can access this with somehow I don't know.
Like X-Plore.(I don't need to install it from Google Play Store but it's working without any problem)

I found an answer from StackOverFlow and I have no idea with these code.

Can anyone please explain me how can I access Android/data on Android 11?

Here's my code!

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

#AdditionalJar: androidx.legacy:legacy-support-core-utils

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private Storage As ExternalStorage
    Private rp As RuntimePermissions
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim b As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    If Not(rp.Check(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)) Then
        MsgboxAsync("I need a permission!","Please,Tap Allow")
        Wait For Msgbox_Result
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        Wait For Activity_PermissionResult(Permission As String,Result As Boolean)
        If Not(Result) Then
            ExitApplication
        End If
    End If
    
    b.Initialize("ALLOW")
    Activity.AddView(b,0,0,100%x,10%y)
    b.Text = "Allow Android Folder"
    If FirstTime Then
        Storage.Initialize (Me, "Storage")
    End If
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub ALLOW_Click
    Storage.SelectDir(True)
    Wait For Storage_ExternalFolderAvailable
    Log(Storage.ListFiles(Storage.Root))
    ToastMessageShow("OK",False)
End Sub
 

agraham

Expert
Licensed User
Longtime User
I am not a java person but this code claims it can access the android folder on android 11
It uses the loophole I described in #16 above which will likely be closed sometime. Give up,restructure your app and stop tilting at windmills.
 
Upvote 0
Top