Joe Asks

^ Why Didn't BrowserIntent Need <uses-permission>?

The previous example, BrowserIntent, simply fired off an intent to request that some other application view the web page. That other application (the browser) is the one that needs to ask for Internet permissions in its own AndroidManifest.xml.

WebView has dozens of other methods you can use to control what is being displayed or get notifications on state changes.

You can find a complete list in the online documentation for WebView, but here are the methods you are most likely to need:

• addJavascriptInterface(): Allows a Java object to be accessed from JavaScript (more on this one in the next section)

• createSnapshot(): Creates a screenshot of the current page

• getSettings( ): Returns a WebSettings object used to control the settings

• loadData( ): Loads the given string data into the browser

• loadDataWithBaseURL(): Loads the given data using a base URL

• loadUrl(): Loads a web page from the given URL

• setDownloadListener( ): Registers callbacks for download events, such as when the user downloads a .zip or .apk file

• setWebChromeClient(): Registers callbacks for events that need to be done outside the WebView rectangle, such as updating the title or progress bar or opening a JavaScript dialog box

• setWebViewClient(): Lets the application set hooks in the browser to intercept events such as resource loads, key presses, and authorization requests

• stopLoading(): Stops the current page from loading

One of the most powerful things you can do with the WebView control is to talk back and forth between it and the Android application that contains it. Let's take a closer look at this feature now.

0 0

Post a comment