Code example for WebView: Displaying web pages

Methods: addJavascriptInterfacegetSettingsloadUrlsetWebChromeClientsetWebViewClient

0
 
  /** Asynchronously open an AppEngine channel. */ 
  @SuppressLint("SetJavaScriptEnabled") 
  public GAEChannelClient( 
      Activity activity, String gaeUrl, MessageHandler handler) {
    webView = new WebView(activity);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebChromeClient(new WebChromeClient() {  // Purely for debugging.
        public boolean onConsoleMessage (ConsoleMessage msg) {
          Log.d(TAG, "console: " + msg.message() + " at " +
              msg.sourceId() + ":" + msg.lineNumber());
          return false; 
        } 
      }); 
    webView.setWebViewClient(new WebViewClient() {  // Purely for debugging.
        public void onReceivedError( 
            WebView view, int errorCode, String description,
            String failingUrl) {
          Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl +
              ", desc: " + description);
        } 
      }); 
    proxyingMessageHandler = new ProxyingMessageHandler(activity, handler);
    webView.addJavascriptInterface(
        proxyingMessageHandler, "androidMessageHandler");
    webView.loadUrl(gaeUrl);
  } 
 
  /** Close the connection to the AppEngine channel. */ 
  public void close() { 
    if (webView == null) {