Android Question ExternalStorage - How to detect if user press BACK key?

artsoft

Active Member
Licensed User
Hi!

I have to write a file to external SD card.

For this I am using this ExternalStorage class:

https://www.b4x.com/android/forum/t...access-sd-cards-and-usb-sticks.90238/#content

My question is now:

How I can detect if the user stopped the choosing of a folder by pressing the BACK key (1 or more times).

In my code (while debugging my app), the debugger doesn't make any halt on any breakpoint after these 2 lines when I am testing exactly this case:

B4X:
Storage.SelectDir(False)
Wait For Storage_ExternalFolderAvailable

In the beginning of using this class ...when I initialize the ExternalStorage object with these commands ...

B4X:
If (Storage.IsInitialized == False) Then
    Storage.Initialize(Me, "Storage")
End If

... how is the name of the event method within my activity code?

Sub Storage_???? () ....

I guess that the string "Storage" is part of the callSubDelayed string "Storage_ExternalFolderAvailable", right?

I hope, somebody can help very quickly.
Thanks a lot in advance.

Regards
ARTsoft
 
Last edited:

artsoft

Active Member
Licensed User
In the older version 1.02 of ExternalStorage (a code lib), I found this:


B4X:
Private Sub SetPickedDir
    Root = DocumentFileToExternalFile(GetPickedDir(PersistantUri))
    CallSubDelayed(mCallback, mEventName & "_ExternalFolderAvailable")
End Sub

Private Sub ion_Event (MethodName As String, Args() As Object) As Object
    If Args(0) = -1 Then 'resultCode = RESULT_OK
        Dim i As Intent = Args(1)
        Dim jo As JavaObject = i
        Dim treeUri As Uri = jo.RunMethod("getData", Null)
        Dim takeFlags As Int = Bit.And(i.Flags, 3)
        ctxt.RunMethodJO("getContentResolver", Null).RunMethod("takePersistableUriPermission", Array(treeUri, takeFlags))
        Dim temp As Object = treeUri
        PersistantUri = temp
        File.WriteString(File.DirInternal, FileName, PersistantUri)
        Log(PersistantUri)
        SetPickedDir
    End If
    Return Null
End Sub

So, we can see that only in case of a successful selection of a folder, the method "SetPickedDir" is called. An this message triggers exactly the "Storage_ExternalFolderAvailable" (what I guess above).

Otherwise I am catched in the WAIT-loop ... :-(

It would be better to set "Root" to Null or something like this - but also in this case the event "Storage_ExternalFolderAvailable" should be triggered!

Is it possible to extend the class (or better the lib) accordingly?
Or what can I do?

Regards
ARTsoft
 
Upvote 0

JohnC

Expert
Licensed User
See if this will help:

 
Upvote 0

artsoft

Active Member
Licensed User
See if this will help:


Hi JohnC!

Yes this helps a lot.
Thanks.

Regards
ARTsoft
 
Upvote 0
Top