使用一个按钮打开文件选择器,使用第二个按钮打开相机应用 android webview kotlin
Open File Chooser with one button and camera app with second button android webview kotlin
我有两个 html 按钮,一个用于上传所有类型的文件,另一个用于打开相机和捕获图像。
#File upload
<input type="file" >
#Open Camera
<input type="file" capture="camera" multiple accept="image/*">
我正在使用 WebChromeClient 在 kotlin 中打开文件选择器,它工作正常,并使用以下代码将文件上传到服务器。
webView.setWebChromeClient(object: WebChromeClient() {
override fun onShowFileChooser(webView:WebView, filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams:FileChooserParams):Boolean {
if (file_permission() && Build.VERSION.SDK_INT >= 21) {
mFilePathCallback = filePathCallback
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.setType("*/*")
startActivityForResult(intent, PICKFILE_REQUEST_CODE)
return true
}else
return false
}
})
我如何将摄像头打开选项与 WebChromeClient 集成,以便它可以检测按下的 html 按钮并相应地打开 intent
也许你可以使用 WebChromeClient.FileChooserParams, It has a method called getTitle()。
来自文档
Returns the title to use for this file selector. If null a default
title should be used.
最后,通过发送控制台消息并在 kotlin 中使用 onConsoleMessage() 捕获它来解决
我有两个 html 按钮,一个用于上传所有类型的文件,另一个用于打开相机和捕获图像。
#File upload
<input type="file" >
#Open Camera
<input type="file" capture="camera" multiple accept="image/*">
我正在使用 WebChromeClient 在 kotlin 中打开文件选择器,它工作正常,并使用以下代码将文件上传到服务器。
webView.setWebChromeClient(object: WebChromeClient() {
override fun onShowFileChooser(webView:WebView, filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams:FileChooserParams):Boolean {
if (file_permission() && Build.VERSION.SDK_INT >= 21) {
mFilePathCallback = filePathCallback
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.setType("*/*")
startActivityForResult(intent, PICKFILE_REQUEST_CODE)
return true
}else
return false
}
})
我如何将摄像头打开选项与 WebChromeClient 集成,以便它可以检测按下的 html 按钮并相应地打开 intent
也许你可以使用 WebChromeClient.FileChooserParams, It has a method called getTitle()。
来自文档
Returns the title to use for this file selector. If null a default title should be used.
最后,通过发送控制台消息并在 kotlin 中使用 onConsoleMessage() 捕获它来解决