android 在B4A中上传文件

3lxsmp7m  于 2022-12-09  发布在  Android
关注(0)|答案(1)|浏览(189)

我是B4X平台的新手,我正在开发一个B4A应用程序,在该应用程序中,我必须将一个文件从我的设备上传到我的本地主机。我在互联网上寻找了一个星期的解决方案,但没有找到任何帮助,

vdgimpew

vdgimpew1#

使用contentchooser库,有关详细信息,您可以使用以下代码

Sub Process_Globals
Private cc As ContentChooser
End Sub

Sub Globals
Private WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
Dim client As JavaObject
client.InitializeNewInstance(Application.PackageName & ".main$MyChromeClient", 
Null)
Dim jo As JavaObject = WebView1
jo.RunMethod("setWebChromeClient", Array(client))
WebView1.LoadUrl("yourwebsite/index.php")
End Sub

Sub ShowFile_Chooser (FilePathCallback As Object, FileChooserParams As Object)
cc.Initialize("CC")
cc.Show("*/*", "Choose File")
Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
Dim jo As JavaObject = Me
If Success Then
    Log(FileName)
    File.Copy(Dir, FileName, Starter.Provider.SharedFolder, "TempFile")
    jo.RunMethod("SendResult", Array(Starter.Provider.GetFileUri("TempFile"), 
FilePathCallback))
Else
    jo.RunMethod("SendResult", Array(Null, FilePathCallback))
End If
End Sub

相关问题