Hi to All
after resolving the access to external sd Card, I went inside another problem, namely how to read the file. It seems a very stupid question, of course. As a matter of fact, once you have an ExternalFile object you can use it for an InputStream etc. This works. But you must have a valid ExternalFile. I did the following test, in which I get the ExternalFile by a FindFile function. Everything works, as I said. Now, if in the folder we have few files, probably a FindFile is fast, but if we have thousands of files? The obvious idea is, knowing exactly the name of the file to read, to use an ExternalFile object, initialize it, assign to it the name of the file and use it, as before. What I see is that this mechanism doesn't work and, "curiously" the debugger returns that the object is not initialized. See the code for understanding better what I mean. the only documentation on this subject is Erel's ExternalStorage lib example. Unluckily in no place I find an explicit initialization of The ExternalFile object. They are all managed as List objects, returned by functions and so on. The app below has a layout with only a Button1. Best regards.
after resolving the access to external sd Card, I went inside another problem, namely how to read the file. It seems a very stupid question, of course. As a matter of fact, once you have an ExternalFile object you can use it for an InputStream etc. This works. But you must have a valid ExternalFile. I did the following test, in which I get the ExternalFile by a FindFile function. Everything works, as I said. Now, if in the folder we have few files, probably a FindFile is fast, but if we have thousands of files? The obvious idea is, knowing exactly the name of the file to read, to use an ExternalFile object, initialize it, assign to it the name of the file and use it, as before. What I see is that this mechanism doesn't work and, "curiously" the debugger returns that the object is not initialized. See the code for understanding better what I mean. the only documentation on this subject is Erel's ExternalStorage lib example. Unluckily in no place I find an explicit initialization of The ExternalFile object. They are all managed as List objects, returned by functions and so on. The app below has a layout with only a Button1. Best regards.
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
#AdditionalJar: androidx.legacy:legacy-support-core-utils ' <<< this is crucial
Sub Process_Globals
Private Storage As ExternalStorage
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Storage.Initialize (Me, "Storage")
End If
Activity.LoadLayout("layout")
End Sub
Sub Button1_Click ' << the only action
Storage.SelectDir(True)
Wait For Storage_ExternalFolderAvailable
Sleep(1000) ' maybe useless
Log(Storage.Root.Name) ' shows correctly the folder previously selected
Dim Name="xxxx.def" As String ' file to read
Dim EZ As ExternalFile
Dim I1,I2 As InputStream
EZ=Storage.FindFile(Storage.Root,Name)
I1=Storage.OpenInputStream(EZ) ' till here OK
Dim EF As ExternalFile ' now the problem
EF.Initialize ' this seems not enough
EF.IsFolder=False
EF.Name=Name
I2=Storage.OpenInputStream(EF) ' Error: java.lang.RuntimeException: Object should first be initialized (JavaObject).
End Sub