Android allows you as a developer to build on the power of the web within your native application, so you can benefit from the flexibility and efficiency of displaying certain types of content.
Embedding content using WebView
The WebView API gives developers access to the capabilities of a mini-browser for displaying web content within your application. This lets you provide web-powered experiences as a core or supporting part within your application, as seen in Figure 1.
What can WebView do?
This is what you can do with WebView in your application:
Embed web: A WebView is integrated into an app's user interface as a component, much like a button or text field.
Load content: WebView can 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 on-the-fly and feed it to the WebView.
Render: WebView uses 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: WebView can execute JavaScript code within the context of the loaded web page. This allows for dynamic interactions and updates within WebView.
Native app interaction: This is where WebView gets more powerful. It allows for bidirectional communication between the web page and the app.
- JavaScript to native: JavaScript code running in WebView can call host APIs of the app, enabling access to device features like camera, GPS, or sensors.
- Native to JavaScript: The app can also inject JavaScript code into WebView, manipulate the web page's content, or respond to events triggered by the web page.
How is WebView different from a typical browser like Chrome?
WebView is a highly custom component which provides the core functionality of a window into the web. Unlike a browser, which provides much of the navigation bar and other user needs to navigate the web more broadly, the overall experience of WebView is shaped by your app's design and purpose.
To better understand how WebView differs from standard browsers, see the following explanations:
UI: WebView is used for displaying web content, and does not have its own header or UI like most other common browsers (home button, URL bar, navigation, settings, etc.)
Features: Many browsers have built additional 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.
Where to start?
For information on how to use WebView in your app, see the article 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 WebView objects
- Support different screens in web apps
- Debug web apps
- Best practices for web apps
- Opt-in to WebView Beta
- In-app browsing using Embedded Web
- Overview of Android Custom Tabs