Android Question Get acceptable file extensions?

JohnC

Expert
Licensed User
Longtime User
If a webpage has an "upload" button on it using the below HTML code:

B4X:
<input type="file" id="file_inputs" class="" accept=".png,.jpg,.jpeg" >

Then, if I use the "Upload file" example here:

https://www.b4x.com/android/forum/threads/upload-files-with-webview.98623/

Is there a way to get that list of acceptable file extensions that are listed in the HTML code? (accept=".png,.jpg,.jpeg")

When the Button is clicked, it invokes the "ShowFile_Chooser" event in the B4A app:
B4X:
Sub ShowFile_Chooser (FilePathCallback As Object, FileChooserParams As Object)

So, I'm thinking that maybe those acceptable file extensions are in the provided FileChooserParams parameter object.

How can this be done?
 

JohnC

Expert
Licensed User
Longtime User
I inserted those two lines in the sub that provides the "FileChooserParams":
B4X:
Sub ShowFile_Chooser (FilePathCallback As Object, FileChooserParams As Object)
    
    Dim jparams As JavaObject = FileChooserParams
    Dim acceptedTypes() As String = jparams.RunMethod("getAcceptTypes", Null)
    
    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
        Dim FN As String = GetFileNameFromContentResult(FileName)
        Log(FileName)
        Log(FN)
        File.Copy(Dir, FileName, Starter.Provider.SharedFolder, FN)
        jo.RunMethod("SendResult", Array(Starter.Provider.GetFileUri(FN), FilePathCallback))
    Else
        jo.RunMethod("SendResult", Array(Null, FilePathCallback))
    End If
End Sub

But, I'm getting an error when it runs the second line:

*** Service (starter) Create ***
Shared Folder: /storage/emulated/0/Android/data/b4a.example/files/shared
Using FileProvider? false
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Cannot get methods of class: com.android.webview.chromium.WebViewContentsClientAdapter$8, disabling cache.
main$ResumableSub_ShowFile_Chooserresume (java line: 445)
java.lang.ClassNotFoundException: com.android.webview.chromium.WebViewContentsClientAdapter$8
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at java.lang.Class.forName(Class.java:272)
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:342)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
at b4a.example.main$ResumableSub_ShowFile_Chooser.resume(main.java:445)
at b4a.example.main._showfile_chooser(main.java:411)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.BA$1.run(BA.java:335)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.webview.chromium.WebViewContentsClientAdapter$8" on path: DexPathList[[zip file "/data/app/b4a.example-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 20 more
Suppressed: java.lang.ClassNotFoundException: com.android.webview.chromium.WebViewContentsClientAdapter$8
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 21 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
That works great - thank you!
 
Upvote 0
Top