Android Question Transition to OS 12.0-API 31

Sergey_New

Well-Known Member
Licensed User
Longtime User
In the attached example, on a device running OS 12.0, a folder is created with the application name "MeApplication" if the manifest specifies
B4X:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
If you set SdkVersion 33 in the manifest, the folder is not created. Please change the example to correct the situation.
 

Attachments

  • test.zip
    3.1 KB · Views: 74

DonManfred

Expert
Licensed User
Longtime User
whenever you see File.DirRootExternal you imediately know it is broken.


FlowChart to help choose folder:
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
whenever you see File.DirRootExternal you imediately know it is broken.
I have already been to the links provided. Unfortunately, my knowledge of Android does not allow me to solve the problem. That's why I asked to modify the example.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
The example is just a few lines of code:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("loader")
    Activity_PermissionResult
End Sub

Sub Activity_PermissionResult
    For Each permission As String In Array(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        rp.CheckAndRequest(permission)
        Wait For Activity_PermissionResult (permission As String, Result As Boolean)
        If Result = False Then
            Activity.Finish
            Return
        End If
    Next
    File.MakeDir(File.DirRootExternal, "MeApplication")
    Try
        Dim lstFiles As List=File.ListFiles(File.DirRootExternal & "/" & "MeApplication")
        Log(lstFiles.Size)
    Catch
        Log(LastException)
    End Try
End Sub
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Nobody can "translate" this code to work with sdk 31. The closest equivalent to this statement ...
B4X:
    File.MakeDir(File.DirRootExternal, "MeApplication")
. . . that will work with curent Android version is . . .
B4X:
    File.MakeDir(xui.DefaultFolder, "MeApplication")
This will create the folder in internal storage, and no external storage permission is needed. If that breaks the functionality of your app then you will have to redesign the app; only you can do that.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
File.MakeDir(xui.DefaultFolder, "MeApplication")
How can the user add the necessary files from the Download folder to this folder?
Will he be able to edit them?
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
How can the user add the necessary files from the Download folder to this folder?
This is not possible. Here is a line taken from one of Erel's posts on this subject.
Not all folders are accessible with ExternalStorage in Android 11+. Specifically, root, Android/data and Download are not accessible.
Here is the link to that post. Now you can see why I don't think that your app can be "translated" to work with current Android. There are many, many posts about this on the forum - just take a look around.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
This is not possible.
If I understand you correctly, then in OS 12.0-API 31 it is impossible to create an application in which the user can add his files to a specially created folder and edit them. This is true?
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I have stopped using external storage; now if I need to share data I FTP it to net storage. None of my apps have many users, so I can use free servers; they provide a couple of hundred megabytes of storage and that is enough for me. What I am saying here is what I have picked up from this forum, not from direct experience. If I am wrong then someone will correct me, I am sure. At the moment nobody seems to be around to join the conversation.

Your app cannot save data to external storage without the User's intervention. The User will choose the folder - you cannot make them use a "specially created folder". Indeed, you cannot create such a folder. If you want to read a file from external storage (using Content Chooser, for example) you must again allow the User to select the folder - you cannot specify a folder. Furthermore, I believe that the User will be restricted in their choice of folder - the Download folder will not be accessible, for example.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
The User will choose the folder
That is, the user himself must create a folder and place the necessary files in it and indicate to the application where they are located?
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
I don't think the application can discover where the file has been saved.
Thank you! Is it really that complicated?
I will try to use [B4X] TextEditor - Save and load external files
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…