2

I want to show my web site as android app. In my code, doesn't work input type=file

I googled "android webview input type file not working".
But only java solution. I want to solve this problem with kotlin.

Anyone has know how to solve this problem?

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    loadWebpage()
}

@Throws(UnsupportedOperationException::class)
fun buildUrl(authority: String) : Uri {
    val builder = Uri.Builder()
    builder.scheme("https")
            .authority(authority)
    return builder.build()
}

fun loadWebpage() {
  try {
        val url = buildUrl("uploader.xzy.pw")
        webview.loadUrl(url.toString())
    } catch(e: UnsupportedOperationException) {
        e.printStackTrace()
    }
  }
}
rluisr
  • 341
  • 6
  • 16

2 Answers2

-1

You could get answer from below link

File Upload in WebView

Then you can convert java code to kotlin by yourself or using android studio.

Sangeet Suresh
  • 2,527
  • 1
  • 18
  • 19
-1

Try this code its working for me

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    private val url = "http://tutorial.eyehunts.com/"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Get the web view settings instance
        val setting = webview.settings;

        // Enable java script in web view
        setting.javaScriptEnabled = true

        webview.loadUrl(url)

    }
}

screenshot webview in android - kotlin

check this : Android WebView app Example in Kotlin

R kanojia
  • 105
  • 4
  • 17