webviewis a powerful component that allows you to display your website or HTML files within the Android application. In this guide, Kotlin You will learn how to develop a professional WebView application from scratch using
Examine every detail step by step, from internet permissions to JavaScript settings, from back button control to local file (Assets) loading. Step into the mobile world with Eka Sunucu.
val myWebView: WebView = findViewById(R.id.webview)
myWebView.settings.javaScriptEnabled = true
myWebView.webViewClient = WebViewClient()
// Web Sitesini Yükle
myWebView.loadUrl("https://www.ekasunucu.com")
Turn your existing website into an app.
HTML/CSS/JS files working without internet.
Activating the JS engine for dynamic content.
Navigating page history within the app.
webview, Android View It is a component derived from the class that allows you to display web pages as part of your application. It's like a browser (like Chrome) without the address bar and navigation buttons.
With this method, you can package your existing responsive website as a "Native" application and publish it on the Google Play Store. It is the fastest application development method for e-commerce sites, blogs and corporate sites.
The first settings you need to make after creating your Android Studio project.
// Be sure to add internet permission
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true">
...
</application>
</manifest>
// A WebView component that maximizes the screen
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
This code places the WebView component to fill the entire screen (match_parent).
Let's configure the WebView in the MainActivity.kt file.
import android.webkit.WebView
import android.webkit.WebViewClient
class MainActivity : AppCompatActivity() {
private lateinit var webView: WebView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// 1. XML'den WebView'ı bul
webView = findViewById(R.id.webView)
// 2. JavaScript'i Aktif Et (Most site for gereklidir)
webView.settings.javaScriptEnabled = true
// 3. Linklerin uygulama in açılmasını sağla
// Bu line olmazsa linkler Chrome browsersında açılır!
webView.webViewClient = WebViewClient()
// 4. URL'yi Yükle
webView.loadUrl("https://www.ekasunucu.com")
}
// 5. Geri Tuşu Checkü
// User geri tuşuna bastığında uygulamadan çıkmak yerine
// bir önceki sayfaya gitmesini provides.
@Deprecated("Deprecated in Java")
override fun onBackPressed() {
if (webView.canGoBack()) {
webView.goBack()
} else {
super.onBackPressed()
}
}
}
If you want your application to run without an internet connection, you can embed your HTML/CSS/JS files into the project.
src/main/assets/ create the folder.index.html) into this folder.webView.loadUrl("file:///android_asset/index.html")
You imagine it, Eka Sunucu expert team will code it.
We turn your existing website into a professional Android application.
Fully device-specific (Native) performance applications instead of WebView.
Technical details about WebView applications
if myWebView.webViewClient = WebViewClient() If you do not add the line, Android operating system will try to open the links in the default browser. This line allows links to be opened within your application (in the WebView component).
Android 9 (Pie) and above by default HTTP blocks sites, just HTTPSIt allows . If your site is HTTP, AndroidManifest.xml to file android:usesCleartextTraffic="true" You must add the line .
WebView does not support File Chooser by default. For file upload feature WebChromeClient class and onShowFileChooser You need to override (customize) its method and obtain the necessary permissions (READ_EXTERNAL_STORAGE).
Yes, you can send notifications to your users by integrating OneSignal or Firebase Cloud Messaging (FCM) into your WebView app. This feature is available in Eka Sunucu's WebView package.
Don't want to deal with coding? We turn your site into a professional Android application within 24 hours and upload it to Google Play.