Hook up the android kotlin code to the send js code (#860)

This commit is contained in:
Donovan Preston 2018-07-27 09:11:46 -04:00 committed by GitHub
parent 5c7b4ace9a
commit a80d007e0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 317 additions and 222 deletions

View file

@ -12,14 +12,16 @@ import android.webkit.WebView
import android.webkit.WebMessage
import android.util.Log
import android.util.Base64
import android.provider.MediaStore
import android.R.attr.data
import android.webkit.ConsoleMessage
import android.webkit.WebChromeClient
internal class LoggingWebChromeClient : WebChromeClient() {
override fun onConsoleMessage(cm: ConsoleMessage): Boolean {
Log.w("CONTENT", String.format("%s @ %d: %s",
cm.message(), cm.lineNumber(), cm.sourceId()))
return true
}
}
class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
private var mWebView: AdvancedWebView? = null
@ -31,6 +33,7 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
mWebView = findViewById<WebView>(R.id.webview) as AdvancedWebView
mWebView!!.setListener(this, this)
mWebView!!.setWebChromeClient(LoggingWebChromeClient())
val webSettings = mWebView!!.getSettings()
webSettings.setJavaScriptEnabled(true)
@ -51,12 +54,8 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
// TODO Currently this causes a Permission Denied error
// val stream = contentResolver.openInputStream(imageUri)
}
mWebView!!.loadUrl("file:///android_asset/intent-target.html")
} else {
mWebView!!.loadUrl("file:///android_asset/index.html")
}
mWebView!!.loadUrl("file:///android_asset/index.html")
}
@SuppressLint("NewApi")