Presentation is loading. Please wait.

Presentation is loading. Please wait.

Webview and Web services. Web Apps You can make your web content available to users in two ways in a traditional web browser in an Android application,

Similar presentations


Presentation on theme: "Webview and Web services. Web Apps You can make your web content available to users in two ways in a traditional web browser in an Android application,"— Presentation transcript:

1 Webview and Web services

2 Web Apps You can make your web content available to users in two ways in a traditional web browser in an Android application, by including a WebView in the layout. There are essentially two ways to deliver an application on Android: as a client-side application (developed using the Android SDK and installed on user devices in an APK) as a web application (developed using web standards and accessed through a web browser—there's nothing to install on user devices). If you chose to provide a web-based app for Android-powered devices, you can rest assured that major web browsers for Android (and the WebView framework) allow you to specify viewport and style properties that make your web pages appear at the proper size and scale on all screen configurations.

3 Web Apps How to provide access to your web pages from either a web browser or your your own Android app. you shouldn't develop an Android app simply as a means to view your web site. Rather, the web pages you embed in your Android app should be designed especially for that environment. You can even define an interface between your Android application and your web pages that allows JavaScript in the web pages to call upon APIs in your Android application—providing Android APIs to your web-based application.

4 Building Web Apps in WebView To deliver a web application (or just a web page) as a part of a client application, you can do it using WebView. WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. does not include any features of a fully developed web browser, such as navigation controls or an address bar. by default, it just show a web page. Scenario 1: when WebView is helpful when you want to provide information in your application that you might need to update, such as an end-user agreement or a user guide. Within your Android application, you can create an Activity that contains a WebView, then use that to display your document that's hosted online.

5 Building Web Apps in WebView Scenario 2: when WebView is helpful if your application provides data to the user that always requires an Internet connection to retrieve data, such as email. In this case, you might find that it's easier to build a WebView in your Android application that shows a web page with all the user data, rather than performing a network request, then parsing the data and rendering it in an Android layout. Instead, you can design a web page that's tailored for Android devices and then implement a WebView in your Android application that loads the web page.

6 What to learn how to get started with WebView how to do some additional things handle page navigation bind JavaScript from your web page to client-side code in your Android application.

7 Adding a WebView to App To add a WebView to your Application, simply include the element in your activity layout. For example, here's a layout file in which the WebView fills the screen: <WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> To load a web page in the WebView, use loadUrl(). For example: WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.loadUrl("http://www.example.com"); Before this will work, however, your application must have access to the Internet. To get Internet access, request the INTERNET permission in your manifest file. For example:... That's all you need for a basic WebView that displays a web page.


Download ppt "Webview and Web services. Web Apps You can make your web content available to users in two ways in a traditional web browser in an Android application,"

Similar presentations


Ads by Google