Android lets you build on the power of the web within your app. So, you can benefit from the flexibility and efficiency of displaying certain types of content.
Embedding content using WebView
The WebView API gives you access to the capabilities of a mini-browser
for displaying web content within your app. This lets you provide web-powered
experiences as a core or supporting part within your app, as seen in Figure
1.
What WebView can do
You can do the following with WebView in your app:
Embed web: A
WebViewis integrated into an app's user interface as a component, much like a button or text field.Load content:
WebViewcan load web content from various sources:- Remote URLs: It can fetch and display web pages from the internet, just like a regular browser.
- Local files: It can load HTML, CSS, and JavaScript files stored within the app's resources.
- Dynamically generated content: The app can generate HTML content dynamically
and provide it to the
WebView.
Render:
WebViewuses its browser engine to parse and render the HTML, CSS, and JavaScript, displaying the resulting web page within its designated area in the app's UI.Execute JavaScript:
WebViewcan execute JavaScript code within the context of the loaded web page. This allows for dynamic interactions and updates within theWebView.Interact with your app: This is where
WebViewgets more powerful. It enables bidirectional communication between the web page and the app.JavaScript to app code: JavaScript code running in a
WebViewcan call host APIs of the app, enabling access to device features like camera, GPS, or sensors.App code to JavaScript: The app can also inject JavaScript code into a
WebView, manipulate the web page's content, or respond to events triggered by the web page.
How WebView differs from a browser
A WebView is a highly custom component that provides the core functionality of
a window into the web. Unlike a browser, which provides a navigation bar and
other user interface elements to navigate the web more broadly, the overall
experience of a WebView is shaped by your app's design and purpose.
To better understand how WebView differs from standard browsers, see the
following explanations:
UI: A WebView is used for displaying web content and doesn't have its own
header or UI like most other common browsers, for example, a home button,
address bar, or settings menu.
Features: Many browsers have built-in features to augment the browsing experience, such as bookmarks, permissions, or history.
Updates: Because Android WebView is a system service on Android, updates
are pushed and integrated into the apps automatically on a monthly basis.
Browsers rely on their corresponding app updates and then for end users to apply
the update on their devices.
Get started
For information on how to use WebView in your app, see the document
Build web apps in WebView.
Additional resources
To develop web pages for Android-powered devices using WebView objects or
Custom Tabs, see the following documents:
- Build web apps in
WebView - Manage
WebViewobjects - Support different screens in web apps
- Debug web apps
- Best practices for web apps
- Opt-in to
WebViewBeta - In-app browsing using embedded web
- Overview of Android Custom Tabs