Я выбираю фото в веб-просмотре:
private var mFilePathCallback: ValueCallback<*>? = null
WebChromeClient() {
override fun onShowFileChooser( webView: WebView, filePathCallback:ValueCallback<Array<Uri>>, fileChooserParams:WebChromeClient.FileChooserParams): Boolean {
mFilePathCallback = filePathCallback
Log.d(TAG, "onShowFileChooser")
}
// For Android 3.0+
fun openFileChooser(uploadMsg: ValueCallback<Uri>) {
mFilePathCallback = uploadMsg
}
// For Android 3.0+
fun openFileChooser(uploadMsg: ValueCallback<*>, acceptType: String){
mFilePathCallback = uploadMsg
}
//For Android 4.1
fun openFileChooser(uploadMsg: ValueCallback<Uri>, acceptType: String, capture: String) {
mFilePathCallback = uploadMsg
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Log.d(TAG, "pick image build version >= LOLLIPOP")
mFilePathCallback!!.onReceiveValue(arrayOf<Uri>(uri)) // it occours error type mismatch
} else {
Log.d(TAG, "pick image build version less than LOLLIPOP")
mFilePathCallback!!.onReceiveValue(uri) // it occours error type mismatch
}
}