In my webview upload image button not working but in browser it's working?

时光怂恿深爱的人放手 提交于 2020-05-09 17:25:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!