问题
In my webview upload image button not working but on browser it's working good but not in my webview app? My app is in Kotlin not Java. Anybody know how to solve this issue. I just want to upload an image by this button.
on browser image:
mainactivity.kt
package com.little.example
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.webkit.WebBackForwardList
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import com.little.example.R
import kotlinx.android.synthetic.main.activity_main.*
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import androidx.core.app.ComponentActivity
import androidx.core.app.ComponentActivity.ExtraData
import androidx.core.content.ContextCompat.getSystemService
import android.icu.lang.UCharacter.GraphemeClusterBreak.T
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
webview.settings.javaScriptEnabled = true
webview.loadUrl("https://little.com")
webview.webViewClient = MyWebViewClient()
}
override fun onBackPressed() {
if (webview.canGoBack()){
webview.goBack()
}
else {
super.onBackPressed()
}
}
private inner class MyWebViewClient : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
if (!url.contains("little.com")) {//for example
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
return true
}
view.loadUrl(url)
return false
}}
}
回答1:
please add into your Webview
settings, below the webview.settings.javaScriptEnabled = true
:
webview.settings.domStorageEnabled = true
来源:https://stackoverflow.com/questions/60612432/in-my-webview-upload-image-button-not-working-but-in-browser-its-working