comp194 ma l.
Skip this Video
Loading SlideShow in 5 Seconds..
Lecture 4: Embedded browsers PowerPoint Presentation
Download Presentation
Lecture 4: Embedded browsers

Loading in 2 Seconds...

play fullscreen
1 / 13

Lecture 4: Embedded browsers - PowerPoint PPT Presentation

  • Uploaded on

Comp194-MA. Lecture 4: Embedded browsers. Motivation. There are several reasons why an application may want to have access to a web browser. Example: display HTML fragments, access external services, open Google search ect.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Lecture 4: Embedded browsers' - Roberta

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
  • There are several reasons why an application may want to have access to a web browser.
  • Example: display HTML fragments, access external services, open Google search ect.
  • Additionally, accessing HTTP resources without a web browser abstraction layer is tedious and unnecessary.
android s solution
Android’s solution
  • Android provides two solutions to this issue:
    • Use an Intent to cause Android to launch its own system browser.
    • Embed a WebView controller inside an Activity
  • Both of these approaches have their own unique advantages and disadvantages.
android intents
Android intents
  • The Android intents are an abstraction that allow activities to easily launch other activities.
  • The platform ships with a dozen or so default intents. They allow things like launching a telephone call, viewing a contact, and of course opening the web browser.
intents pros cons
Intents pros/cons
  • Launching an intent to handle browsing utilizes the built in Android browser which is more robust than WebView.
  • The built in browser comes with “helpers” like a status bar, loading bar, ect.
  • The major con is that the application looses control of the phone when the browser is launched.
  • There is no way to intercept events or force the user back into an application.
using webview
Using WebView
  • The WebView controller allows for HTML fragments and web pages to be displayed in an activity.
  • WebView interacts with an Android activity like any other widget.
  • As such, an activity can capture events and as well as interact with the DOM on the page.
  • Unfortunately, the WebView implementation does not support AJAX out of the box.
intent code
Intent Code

Intent i = new Intent();



Uri uri = Uri.parse(fbClient.getLoginURL(authToken));

i.setData(uri); // set the URL you want to open here

fb.startActivity(i); // fire the event

// Your activity will continue running while the browser is open.

// The user can return to your activity if they hit “back” on the phone’s hard buttons.

webview code
WebView Code

Embed in a layout.xml file:

<WebView android:id="@+id/webview" android:layout_width="fill_parent“ android:layout_height="0dip" android:layout_weight="1" />

To navigate to a page:

WebView wv = (WebView) fb.findViewById(;


wv.setWebViewClient(new WebViewClient(){


public boolean shouldOverrideUrlLoading(WebView view, String url) {

return false;


webview gotcha s
  • WebView has a lot of unintuitive default behavior.
  • For example: by default WebView will open links in a new Android browser window.
  • To override this, pass the WebView controller a WebViewClient with the right functions overridden.
webview example
WebView example
  • In the example code:

public boolean shouldOverrideUrlLoading (WebView view, String url) {

return false;


  • Overriding shouldOverrideUrlLoading and returning false will cause WebView to load links.
  • In order for WebView to access the internet your application needs the android.permission.INTERNET permission.
  • Network latency can be simulated using the DDMS console.
  • You probably want to set WebView to fill_parent since small browsers are no fun.
  • As of SDK 1.1 R1 WebView loads HTTP over SSL URLs particularly slowly.
google docs
Google docs
the project
The Project
  • This is a big one so we’ll break it into two weeks.
  • Goal: Use the Facebook API to load the photos for the contacts in the phone.
  • Issues: How to interface with Facebook? How to create a contact? How to download photos? (???)