Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.polsl.lab6v2022
- import android.content.pm.ActivityInfo
- import androidx.appcompat.app.AppCompatActivity
- import android.os.Bundle
- import android.webkit.JavascriptInterface
- import android.webkit.WebView
- class Kartka : AppCompatActivity() {
- var myString: String = ""
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- //WebView - kontrolka wyswietlajaca html
- val page = WebView(this)
- if (savedInstanceState != null) {
- myString = savedInstanceState.getString("giftsList", "")
- } else {
- myString = intent.getStringExtra("giftsList")!!
- }
- //wlaczenie obslugi JS
- page.settings.javaScriptEnabled=true
- //dodanie interfejsu pomiędzy Kotlinem a JS
- //this - obiekt tej klasy dostarcza metody JSInterface, activity - nazwa widoczna w JS
- page.addJavascriptInterface(this, "activity") //ODKOMENTOWAC DLA JS
- //zaladowanie zawartosci kontroli WebView - pliki z katalogu assests w projekcie
- page.loadUrl("file:///android_asset/Kartka.html")
- this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
- //wstawienie kontrolki WebView jako calej fasady aktywnosci
- setContentView(page)
- }
- override fun onSaveInstanceState(outState: Bundle) {
- super.onSaveInstanceState(outState)
- outState.putString("giftsList", myString)
- }
- @JavascriptInterface
- fun getGifts(): String {
- return myString
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement