AI2 Component  (Version nb184) Class Reference
Inheritance diagram for


class  WebViewInterface

Public Member Functions

 WebViewer (ComponentContainer container)
String WebViewString ()
void WebViewString (String newString)
View getView ()
void Width (int width)
void Height (int height)
String HomeUrl ()
void HomeUrl (String url)
String CurrentUrl ()
String CurrentPageTitle ()
boolean FollowLinks ()
void FollowLinks (boolean follow)
boolean IgnoreSslErrors ()
void IgnoreSslErrors (boolean ignoreSslErrors)
void GoHome ()
void GoBack ()
void GoForward ()
boolean CanGoForward ()
boolean CanGoBack ()
void GoToUrl (String url)
void StopLoading ()
void Reload ()
void UsesLocation (boolean uses)
boolean PromptforPermission ()
void PromptforPermission (boolean prompt)
void ClearLocations ()
void ClearCaches ()
void ClearCookies ()
void RunJavaScript (String js)
void WebViewStringChange (String value)
void BeforePageLoad (String url)
void PageLoaded (String url)
void ErrorOccurred (int errorCode, String description, String failingUrl)
- Public Member Functions inherited from
boolean Visible ()
void Visible (boolean visibility)
int Width ()
void WidthPercent (int pCent)
void setLastWidth (int width)
int getSetWidth ()
void setLastHeight (int height)
int getSetHeight ()
void CopyWidth (AndroidViewComponent sourceComponent)
int Height ()
void HeightPercent (int pCent)
void CopyHeight (AndroidViewComponent sourceComponent)
int Column ()
void Column (int column)
int Row ()
void Row (int row)
HandlesEventDispatching getDispatchDelegate ()

Additional Inherited Members

- Static Public Attributes inherited from
static final String ASSET_DIRECTORY = "component"
static final int ALIGNMENT_NORMAL = 0
static final int ALIGNMENT_CENTER = 1
static final int ALIGNMENT_OPPOSITE = 2
static final int BUTTON_SHAPE_DEFAULT = 0
static final int BUTTON_SHAPE_ROUNDED = 1
static final int BUTTON_SHAPE_RECT = 2
static final int BUTTON_SHAPE_OVAL = 3
static final int COLOR_NONE = 0x00FFFFFF
static final int COLOR_BLACK = 0xFF000000
static final int COLOR_BLUE = 0xFF0000FF
static final int COLOR_CYAN = 0xFF00FFFF
static final int COLOR_DKGRAY = 0xFF444444
static final int COLOR_GRAY = 0xFF888888
static final int COLOR_GREEN = 0xFF00FF00
static final int COLOR_LTGRAY = 0xFFCCCCCC
static final int COLOR_MAGENTA = 0xFFFF00FF
static final int COLOR_ORANGE = 0xFFFFC800
static final int COLOR_PINK = 0xFFFFAFAF
static final int COLOR_RED = 0xFFFF0000
static final int COLOR_WHITE = 0xFFFFFFFF
static final int COLOR_YELLOW = 0xFFFFFF00
static final int COLOR_DEFAULT = 0x00000000
static final String DEFAULT_VALUE_COLOR_NONE = "&H00FFFFFF"
static final String DEFAULT_VALUE_COLOR_BLACK = "&HFF000000"
static final String DEFAULT_VALUE_COLOR_BLUE = "&HFF0000FF"
static final String DEFAULT_VALUE_COLOR_CYAN = "&HFF00FFFF"
static final String DEFAULT_VALUE_COLOR_DKGRAY = "&HFF444444"
static final String DEFAULT_VALUE_COLOR_GRAY = "&HFF888888"
static final String DEFAULT_VALUE_COLOR_GREEN = "&HFF00FF00"
static final String DEFAULT_VALUE_COLOR_ORANGE = "&HFFFFC800"
static final String DEFAULT_VALUE_COLOR_RED = "&HFFFF0000"
static final String DEFAULT_VALUE_COLOR_DEFAULT = "&H00000000"
static final float FONT_DEFAULT_SIZE = 14
static final int SCALING_SCALE_TO_FIT = 1
static final int TYPEFACE_DEFAULT = 0
static final int TYPEFACE_SANSSERIF = 1
static final int TYPEFACE_SERIF = 2
static final int TYPEFACE_MONOSPACE = 3
static final int LENGTH_PREFERRED = -1
static final int LENGTH_FILL_PARENT = -2
static final int LENGTH_UNKNOWN = -3
static final int LENGTH_PERCENT_TAG = -1000
static final int TOAST_LENGTH_SHORT = 0
static final int TOAST_LENGTH_LONG = 1
static final int DIRECTION_NORTH = 1
static final int DIRECTION_NORTHEAST = 2
static final int DIRECTION_EAST = 3
static final int DIRECTION_SOUTHEAST = 4
static final int DIRECTION_SOUTH = -1
static final int DIRECTION_SOUTHWEST = -2
static final int DIRECTION_WEST = -3
static final int DIRECTION_NORTHWEST = -4
static final int DIRECTION_NONE = 0
static final int DIRECTION_MIN = -4
static final int DIRECTION_MAX = 4
static float SLIDER_MIN_VALUE = 10
static float SLIDER_MAX_VALUE = 50
- Protected Member Functions inherited from
 AndroidViewComponent (ComponentContainer container)
- Protected Member Functions inherited from
 VisibleComponent ()
- Protected Attributes inherited from
final ComponentContainer container

Detailed Description

Component for viewing Web pages.

WebViewer icon

The HomeUrl() can be specified in the Designer or in the Blocks Editor. The view can be set to follow links when they are tapped, and users can fill in Web forms.

Warning: This is not a full browser. For example, pressing the phone's hardware Back key will exit the app, rather than move back in the browser history.

You can use the WebViewString(String) property to communicate between your app and Javascript code running in the WebViewer page. In the app, you get and set WebViewString(String). In the WebViewer, you include Javascript that references the window.AppInventor object, using the methods getWebViewString() and setWebViewString(text).

For example, if the WebViewer opens to a page that contains the Javascript command

document.write("The answer is" + window.AppInventor.getWebViewString());

and if you set WebViewString(String) to "hello", then the web page will show

The answer is hello.

And if the Web page contains Javascript that executes the command

windowAppInventor.setWebViewString("hello from Javascript"),

then the value of the WebViewString() property will be

hello from Javascript.

Calling setWebViewString from JavaScript will also run the WebViewStringChange(String) event so that the blocks can handle when the WebViewString(String) property changes.

@internaldoc Component for displaying web pages This is a very limited form of browser. You can view web pages and click on links. It also handles Javascript. There are lots of things that could be added, but this component is mostly for viewing individual pages. It's not intended to take the place of the browser.

Author (Hal Abelson)

Definition at line 107 of file

Constructor & Destructor Documentation

◆ WebViewer() ( ComponentContainer  container)

Creates a new WebViewer component.

containercontainer the component will be placed in

Definition at line 136 of file

Member Function Documentation

◆ BeforePageLoad()

void ( String  url)

Definition at line 570 of file

◆ CanGoBack()

boolean ( )
true if the WebViewer can go back in the history list

Definition at line 426 of file

◆ CanGoForward()

boolean ( )
true if the WebViewer can go forward in the history list

Definition at line 416 of file

◆ ClearCaches()

void ( )

Clear the internal webview cache, both ram and disk. This is useful when using the WebViewer to poll a page that may not be sending appropriate cache control headers.

Definition at line 531 of file

◆ ClearCookies()

void ( )

Clear the webview's cookies. This is useful if you want to sign the user out of a website that uses them to store logins.

Definition at line 540 of file

◆ ClearLocations()

void ( )

Clear Stored Location permissions. When the geolocation API is used in the WebViewer, the end user is prompted on a per URL basis for whether or not permission should be granted to access their location. This function clears this information for all locations.

As the permissions interface is not available on phones older then Eclair, this function is a no-op on older phones.

Definition at line 512 of file

◆ CurrentPageTitle()

String ( )

Returns the title of the page currently being viewed

title of the page being viewed

Definition at line 317 of file

◆ CurrentUrl()

String ( )

Returns the URL currently being viewed. This could be different from the HomeUrl() if new pages were visited by following links.

URL of the page being viewed

Definition at line 305 of file

◆ ErrorOccurred()

void ( int  errorCode,
String  description,
String  failingUrl 

Definition at line 580 of file

◆ FollowLinks() [1/2]

boolean ( )

Indicates whether to follow links when they are tapped in the WebViewer

true or false

Definition at line 329 of file

◆ FollowLinks() [2/2]

void ( boolean  follow)

Determines whether to follow links when they are tapped in the WebViewer. If you follow links, you can use GoBack() and GoForward() to navigate the browser history.


Definition at line 342 of file

◆ getView()

View ( )

Returns the View that is displayed in the UI.

Reimplemented from

Definition at line 201 of file

◆ GoBack()

void ( )

Go back to the previous page in the history list. Does nothing if there is no previous page.

Definition at line 393 of file

◆ GoForward()

void ( )

Go forward to the next page in the history list. Does nothing if there is no next page.

Definition at line 405 of file

◆ GoHome()

void ( )

Loads the page from the home URL. This happens automatically when home URL is changed.

Definition at line 383 of file

◆ GoToUrl()

void ( String  url)

Load the page at the given URL.

Definition at line 436 of file

◆ Height()

void ( int  height)

Specifies the type%'s vertical height, measured in pixels.

heightin pixels

Reimplemented from

Definition at line 258 of file

◆ HomeUrl() [1/2]

String ( )

Returns the URL of the page the WebVewier should load

URL of the page the WebVewier should load

Definition at line 275 of file

◆ HomeUrl() [2/2]

void ( String  url)

Specifies the URL of the page the WebViewer should initially open to. Setting this will load the page.

urlURL of the page the WebVewier should load

Definition at line 288 of file

◆ IgnoreSslErrors() [1/2]

boolean ( )

Determine whether or not to ignore SSL errors. Set to true{:.logic.block} to ignore errors. Use this to accept self signed certificates from websites.

true or false

Definition at line 358 of file

◆ IgnoreSslErrors() [2/2]

void ( boolean  ignoreSslErrors)

Determines whether or not to ignore SSL Errors


ignoreSslErrorsset to true to ignore SSL errors

Definition at line 371 of file

◆ PageLoaded()

void ( String  url)

Definition at line 575 of file

◆ PromptforPermission() [1/2]

boolean ( )

Determine if the user should be prompted for permission to use the geolocation API while in the webviewer.

true if prompting is required. False assumes permission is granted.

Definition at line 482 of file

◆ PromptforPermission() [2/2]

void ( boolean  prompt)

Determine if the user should be prompted for permission to use the geolocation API while in the WebViewer. If true{:.logic.block}, prompt the user of the WebViewer to give permission to access the geolocation API. If false{:.logic.block}, assume permission is granted.

promptset to true to require prompting. False assumes permission is granted.

Definition at line 498 of file

◆ Reload()

void ( )

Reload the current page.

Definition at line 454 of file

◆ RunJavaScript()

void ( String  js)

Run JavaScript in the current page.

Definition at line 553 of file

◆ StopLoading()

void ( )

Stop loading a page.

Definition at line 445 of file

◆ UsesLocation()

void ( boolean  uses)

Specifies whether or not this WebViewer can access the JavaScript geolocation API.

uses– Whether or not the API is available

Definition at line 469 of file

◆ WebViewString() [1/2]

String ( )

Gets the WebView's String, which is viewable through Javascript in the WebView as the window.AppInventor object.


Definition at line 186 of file

◆ WebViewString() [2/2]

void ( String  newString)

Sets the web view string


Definition at line 196 of file

◆ WebViewStringChange()

void ( String  value)

Event that runs when the AppInventor.setWebViewString method is called from JavaScript. The new WebViewString() is given by the value{:.variable.block} parameter.


Definition at line 565 of file

◆ Width()

void ( int  width)

Specifies the horizontal width of the type%, measured in pixels.

widthin pixels

Reimplemented from

Definition at line 245 of file

The documentation for this class was generated from the following file: