Build a simple Android browser with WebView
Android’s WebView component can display most websites inside an app, making it useful for a focused reader, a help centre or a browser prototype. It loads remote HTML using Android’s browser rendering engine while the app controls the toolbar, navigation, page titles and error messages.
Building a simple web browser with WebView requires more than placing a WebView on the screen. The app needs internet permission, a WebViewClient, address handling and sensible controls for back navigation. Beginners can use the standard Android SDK and Kotlin without a third-party browser engine; Android Open Tutorials also provides related examples for Android UI components and persistence.
For Australian users, the example should account for reliable mobile broadband, intermittent café Wi-Fi and the Android devices widely sold through local electronics retailers. It should also feel familiar: Australian English, 24-hour times, clear privacy choices and easy access to Australian news and government services.
Create the project and browser layout
Open Android Studio, create an Empty Views Activity, choose Kotlin and select a reasonable minimum SDK such as 23. WebView is part of Android, so no browser library is required. Give the activity a WebView for page content, an EditText for the address, and buttons for Back, Forward and Reload; a ProgressBar can show loading activity.
Use a vertical LinearLayout in activity_main.xml. Let the WebView occupy the remaining height while the address field and buttons sit above it.
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<EditText
android:id="@+id/addressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textUri" />
Set meaningful content descriptions on icon buttons, and keep the controls large enough to use with one hand.
Enable network access and safe loading
Add the internet permission to AndroidManifest.xml. Android does not grant network access to an app by default, even when its central feature is a website.
<uses-permission android:name="android.permission.INTERNET" />
Configure the WebView in the activity. JavaScript is required by many sites, including Australian news portals and booking services, but it also increases the app’s exposure to malicious pages. Keep the client attached to the WebView so navigation remains inside the app.
webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.settings.allowFileAccess = false
webView.settings.allowContentAccess = false
webView.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
progressBar.isVisible = true
}
override fun onPageFinished(view: WebView, url: String) {
progressBar.isVisible = false
addressBar.setText(url)
}
}
Handle onReceivedError as well. A failed request should produce a clear retry message rather than an unexplained blank screen, particularly when a mobile connection becomes unstable.
Route navigation between the app and other apps
Use shouldOverrideUrlLoading to decide where each link belongs. Ordinary http and https pages should remain in the WebView. A mailto or tel link can open a compatible Android app, while a custom mapping or payment scheme should be launched externally only when an appropriate handler exists.
The routing decision can be matched to each destination:
| Destination | Action | Reason |
|---|---|---|
| HTTP and HTTPS pages | Keep the page in the WebView | Preserves toolbar state and browsing history |
mailto and tel links |
Open a matching Android app | Uses the device’s preferred mail or phone handler |
| Maps and custom schemes | Open an external app when available | Avoids an empty WebView or unsupported-page error |
| Unsupported addresses | Show a local error message | Prevents a silent failure |
Return false for web addresses so WebView can load them. For an external intent, catch ActivityNotFoundException and show a message if the device has no suitable app. This separation also keeps ordinary link taps inside the simple browser without trapping users in a non-web destination.
Add navigation controls and page feedback
Connect the toolbar buttons to the WebView’s history API. The Back button should move through visited pages before it closes the activity, while Forward and Reload act on the current page.
backButton.setOnClickListener {
if (webView.canGoBack()) webView.goBack() else finish()
}
forwardButton.setOnClickListener {
if (webView.canGoForward()) webView.goForward()
}
reloadButton.setOnClickListener { webView.reload() }
Also handle the system Back gesture or button with the app’s back dispatcher. Repeated Back presses can expose WebView history that differs from the visible browser toolbar, so update the button states whenever navigation finishes.
When the user submits an address, trim whitespace, accept only http and https, and add https:// when the scheme is missing. Reject javascript: and local-file schemes from typed input because they can bypass the normal web navigation model. Hide the keyboard after loading and give the address field an Australian news address as its initial value.
Tailor behaviour for Australian users
An Australian build can use Australian English spellings and, where dates or times appear, the familiar 24-hour clock. Local examples include ABC News, news.com.au, and state government portals such as NSW Government and Victoria’s official services. These sites often mix responsive pages, video, cookies and redirects, making them useful test cases for a small browser.
Connectivity patterns vary from fast 5G in central Sydney or Melbourne to patchy café Wi-Fi and regional mobile coverage. Preserve normal browser caching, show a progress state during slow responses and avoid replacing an error screen every time a network request fails. The app should recover cleanly when connectivity returns.
The Australian handset market includes Samsung, Google and Motorola models sold through JB Hi-Fi, Harvey Norman, mobile carriers and prepaid retailers. Test at least one Samsung Galaxy device, a smaller or lower-memory phone and a tablet. This exposes cramped toolbars, font-scaling problems and differences in WebView rendering that may remain hidden on a developer emulator.
Test and package the browser
Start the release pass with these security and behaviour checks:
- Confirm that ordinary links stay in the WebView, while
telandmailtolinks open only installed handlers. - Enter
javascript:,file://and malformed addresses to verify that the app rejects unsafe input. - Exercise redirects, expired certificates and failed requests to confirm that errors remain understandable.
Continue with device and distribution checks:
- Test Back and Forward during redirects, slow mobile broadband and transitions between offline and online states.
- Check the address bar and controls on a compact Galaxy phone, a tablet and a large system font size.
- Verify that videos, forms, cookies and JavaScript-dependent Australian sites behave consistently across supported Android versions.
Create a release keystore, keep it outside version control, and enable shrinking only after tests pass. Upload an Android App Bundle to Google Play after testing an update over an existing installation, since WebView cookies, cached pages and history can behave differently after replacement. Release and debug builds use the same supported Android API levels, preventing users from receiving a browser with broken navigation or missing network access.