Android Question [SOLVED]Problem with ExternalFile object

zolive33

Active Member
Licensed User
Longtime User
hi,

I try to create a new file in the dowload folder. The file is created but does not seem to be initialized (IsInitialized returns false).
is it normal?


here is an example :

B4X:
dim Storage As ExternalStorage
Dim ef As ExternalFile

Storage.Initialize (Me, "Storage")
Storage.SelectDir(false)
Wait For Storage_ExternalFolderAvailable

ef = Storage.CreateNewFile(Storage.Root,"test.txt")
log (ef.IsInitialized) 'always returns false

Running on Android 10 :
1614717714390.png

log extract :
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
content://com.android.providers.downloads.documents/tree/downloads
** Activity (main) Resume **
false

Here's a solution that works but it's a bad solution :
B4X:
Do While Not(ef.IsInitialized)
    ef = Storage.FindFileOrCreate(Storage.Root,"test.txt")
Loop
log (ef.IsInitialized) 'ok

log extract :
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
content://com.android.providers.downloads.documents/tree/downloads
** Activity (main) Resume **
true


Have you another solution ?
 
Last edited:

amykonio

Active Member
Licensed User
Longtime User
Hi.
Have you tried to put your code in a try catch block to see if an error occurs?

Andreas.
 
Upvote 0

zolive33

Active Member
Licensed User
Longtime User
problem solved :

B4X:
Dim iRedo As Int=0
Do While (Not(ef.IsInitialized) And iRedo<2)
    ef = Storage.FindFileOrCreate(Storage.Root,"test.txt")
    Sleep(30)
    iRedo = iRedo+1
Loop
log (ef.IsInitialized) 'ok
 
Upvote 0
Top