如何解决如何在Android WebView中拍照或选择图库文件
文件上传效果很好,问题在于它不允许我拍照,我已经尝试过以各种方式修改代码,但是它不起作用。
如何进行调整以使两个选项均起作用,如何确定选择了哪个选项(拍照,选择文件)?
角度代码
HTML
<input
#inputFile
accept="image/*,application/pdf"
type="file"
(change)="loadFile($event)"
style="display: none;"
onclick="this.value = null"
/>
<input
#cameraFile
accept="image/*"
capture="camera"
type="file"
(change)="loadFile($event)"
style="display: none;"
onclick="this.value = null"
/>
Ts
selectOption(opcion: any) {
if (opcion.tipoArchivo === this.documentType.documento.idDocumento) {
switch (opcion.opcion) {
case MenuBottomSheet.ELEGIR_FOTO:
this.fileChooser.nativeElement.click();
break;
case MenuBottomSheet.TOMAR_FOTO:
this.cameraFile.nativeElement.click();
break;
}
}
}
Códigoandroid
web_view?.webChromeClient = object: WebChromeClient() {
override fun onShowFileChooser(webView: WebView?,filePathCallback: ValueCallback<Array<Uri>>?,fileChooserParams: FileChooserParams): Boolean {
Log.d("onShowFileChooser ======> ","")
super.onShowFileChooser(webView,filePathCallback,fileChooserParams)
if (uploadMessage != null) {
uploadMessage?.onReceiveValue(null)
uploadMessage = null
}
uploadMessage = filePathCallback
val intent: Intent = fileChooserParams.createIntent()
try {
startActivityForResult(intent,REQUEST_SELECT_FILE)
} catch (e: ActivityNotFoundException) {
uploadMessage = null
return false
}
return true
}
}
override fun onActivityResult(requestCode: Int,resultCode: Int,data: Intent?) {
super.onActivityResult(requestCode,resultCode,data)
if (resultCode == RESULT_OK && (requestCode == REQUEST_SELECT_FILE || requestCode == REQUEST_IMAGE_CAPTURE)) {
if (uploadMessage == null) {
return
}
uploadMessage?.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode,data))
uploadMessage = null
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。