基于Web的相关内容(Web-based content)
翻译地址:https://developer.android.google.cn/guide/webapps
Android offers a variety of ways to present content to a user. To provide a user experience that’s consistent with the rest of the platform, it’s usually best to build a native app that incorporates framework-provided experiences, such as Android App Links or Search. Additionally, you can use Google Play-based experiences, such as App Actions and Slices, where Google Play services is available. Some apps, however, may need increased control over the UI. In this case, a WebView is a good option for displaying trusted first-party content.
Android提供了多种方式向用户呈现内容。为了提供与平台其他部分一致的用户体验,通常最好构建一个包含框架提供的体验的本地应用程序,比如Android应用程序链接或搜索。此外,您还可以使用基于谷歌播放的体验,例如应用程序操作和切片,其中可以使用谷歌播放服务。然而,有些应用程序可能需要加强对UI的控制。在这种情况下,WebView是显示可信的第一方内容的好选项。
Figure 1. You can make your web content available to users in two ways: in a traditional web browser and in an Android application, by including a WebViewin the layout. 您可以通过两种方式向用户提供web内容:在传统web浏览器和Android应用程序中,在布局中包含webview。Figure 1 illustrates how you can provide access to your web pages from either a browser or your own Android app. The WebViewframework allows you to specify viewport and style properties that make your web pages appear at the proper size and scale on all screen configurations for all major web browsers. You can even define an interface between your Android app and your web pages that allows JavaScript in the web pages to call upon APIs in your app—providing Android APIs to your web-based application.
图1演示了如何提供访问你的网页浏览器或自己的Android应用程序。WebView框架允许您指定视窗和样式属性,使你的网页出现在所有屏幕上正确的大小和规模配置主流web浏览器。您甚至可以在Android应用程序和web页面之间定义一个接口,该接口允许web页面中的JavaScript调用应用程序中的api—为基于web的应用程序提供Android api。
However, you shouldn't develop an Android app simply as a means to view your website. Rather, the web pages you embed in your app should be designed especially for that environment.
然而,你不应该简单地开发一个Android应用程序来浏览你的网站。相反,应用程序中嵌入的web页面应该专门针对这种环境设计。