Android Question Browse files from the server with

AlfaizDev

Well-Known Member
Licensed User
hi
I want to browse files from the server with
ContentChooser
or
FileDialog
 

DonManfred

Expert
Licensed User
Longtime User
Both are only for data on your Device.

There is no such thing like ContentChooser or FileDialog when working with a Server.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Both are only for data on your Device.
This is not 100% correct. You can access remote resources with ContentChooser. For example Google drive files.
You will not be able to access your server files unless there is an app installed that implements a Content Provider that can access your server.

You can use FTP and build your own file dialog.
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
OK
Thank you both
I will look for an alternative like
webweiw
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Is there a way to browse and download files from the local server?
I used a webweiw
But I want a better way
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
We cannot help you as you don't provide enough information. I don't have a clue on what you are doing and how is WebView related here.

OK
Sorry
I'll explain more
I have files on my computer
And I installed a local server program
I created an Android app to view and download files located in the root of the local server
The communication process was successful
I was able to browse and download the files using AdvancedWebView
advWV.loadUrl (ur)
Asking, I want another way to browse files and download them from the server
It has a better width, more flexibility and arrangement than these
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Use this code

B4X:
Dim ur As String = ("http://192.168.1.4/MyFile/")

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    

    
    advWV.CookiesEnabled = True
    advWV.GeolocationEnabled = True
    
    advWV.loadUrl(ur)
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode=KeyCodes.KEYCODE_BACK Then
        advWV.onBackPressed
    'Return    True
    End If
    Return True
End Sub

Sub AdvWv_onDownloadRequested(url As String, suggestedFilename As String, mimeType As String, contentLength As Long, contentDisposition As String, userAgent As String)
    suggestedFilename0=suggestedFilename
'        'Send a GET request
    downloadurl = url
    Dim job As HttpJob
    job.Initialize("Job", Me)
    job.Download(downloadurl)
    ProgressDialogShow("جاري تنزيل الملف")

End Sub
Sub JobDone (job As HttpJob)
    If job.Success Then
        Dim out As OutputStream = File.OpenOutput(File.Combine(File.DirRootExternal, "Download"), suggestedFilename0, True)
        File.Copy2(job.GetInputStream, out)
        out.Close '<------ very important
        ToastMessageShow("تم تنزيل الملف",True)
        'Log( job.GetString2("UTF-8"))
        
    Else
        'Log("Error: " & job.ErrorMessage)
    End If
    job.Release
    ProgressDialogHide
    

End Sub
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
There are millions types of servers. The details depend on the specific server you are using.

If it is an Apache server with the default settings then you can make a request with OkHttpUtils2 to the folder url and parse the result.
Yes it is an Apache server
But I didn't know the way for that
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
It is a good idea to use a PHP File Manager
And linked to it with Webview I used it and liked it
 
Upvote 0
Top