[英]Why 'onShowFileChooser' overrides nothing?
Tell me what I did wrong in my code, why 'onShowFileChooser' overrides nothing?告诉我我在代码中做错了什么,为什么“onShowFileChooser”什么都没有覆盖? The class was created to allow webview to upload files from the phone "webview import file".创建 class 是为了允许 webview 从手机“webview 导入文件”上传文件。
class FileChooseClient(private val activity: ActivityChoser) : WebChromeClient() {
override fun onShowFileChooser(v: WebView?, fpc: ValueCallback<Uri>?, fcp: FileChooserParams): Boolean {
if (activity.uploadMessage != null) {
activity.uploadMessage?.onReceiveValue(null)
activity.uploadMessage = null
}
activity.uploadMessage = fpc
val intent: Intent = fcp.createIntent()
try {
activity.startActivityForResult(intent, ActivityChoser.REQUEST_SELECT_FILE)
(activity as Activity).overridePendingTransition(
android.R.anim.fade_in,
android.R.anim.fade_out
)
} catch (e: ActivityNotFoundException) {
activity.uploadMessage = null
return false
}
return true
}
interface ActivityChoser {
companion object {
const val REQUEST_SELECT_FILE = 100;
}
var uploadMessage: ValueCallback<Uri>?
fun startActivityForResult(intent: Intent, req: Int)
}
} }
Because the second parameter's type is wrong;因为第二个参数的类型不对; it should be 应该是
ValueCallback<Array<Uri>?>
or maybe或者可能
ValueCallback<Array<Uri>?>?
because a file chooser can choose multiple files ( ?
after Array
should definitely be there if I understand the documentation correctly).因为文件选择器可以选择多个文件(如果?
正确理解文档, Array
之后肯定应该存在)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.