Convert Website into Android Application using Kotlin

Get Into Code previously provides you with free C++ and Java Course in Hindi/Urdu and also provides you the opportunity to practice your skills to be perfect. Now, Get Into Code provides you with android development tutorials as well using Kotlin Language, here is the first post which covers How to convert website into android application using kotlin.


  1. Get Started by adding Internet Permission in AndroidManifest.xml file in your android studio.
  2. < uses-permission android:name="android.permission.INTERNET" />
    Now your app have the permission to use internet, without adding above permission to your manifest file, your app will not able to access internet.

  3. Now, add the WebView to your activity_main.xml file in your android studio

    Add the following code to your activity_main.xml file
    <?xml version="1.0" encoding="utf-8"? >
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          tools:context=".MainActivity">
          <WebView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/web_view"/>

    </LinearLayout>

    That's enough with designing.
  4. Now, Get started with MainActivity.kt to produce functionality in your application.
    1. create variable to link WebView from activity_main.xml
      private var mWebView : WebView = findViewById("R.id.web_view") 

    2. Your includes Javascript code, therefore to make your website work properly in your android application requires to enabled JavaScript
      mWebView.settings.javaScriptEnabled = true

    3. To open url in one over the other, you should have to create webViewClient Object
      mWebView.webViewClient = object : WebViewClient() {
         override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
            view?.loadUrl(url)
            return true
          }
      }

    4. Finally add the loadUrl to the mWebView varibale to load your site on to your android application.
      mWebView.loadUrl("https://www.getintocode.site/")

    5. To move back to previous links by pressing back key, instead of closing your android application,
      override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
          if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
           mWebView.goBack()
          return true
         }
      return super.onKeyDown(keyCode, event)
      }

No comments

Powered by Blogger.