コード例 #1
0
  @Override
  public boolean shouldOverrideUrlLoading(final WebView view, String url) {
    if (DBG) {
      Log.d(LCAT, "url=" + url);
    }

    if (URLUtil.isAssetUrl(url) || URLUtil.isContentUrl(url) || URLUtil.isFileUrl(url)) {
      // go through the proxy to ensure we're on the UI thread
      webView.getProxy().setProperty("url", url, true);
      return true;
    } else if (url.startsWith(WebView.SCHEME_TEL)) {
      Log.i(LCAT, "Launching dialer for " + url);
      Intent dialer =
          Intent.createChooser(new Intent(Intent.ACTION_DIAL, Uri.parse(url)), "Choose Dialer");
      webView.getProxy().getTiContext().getActivity().startActivity(dialer);
      return true;
    } else if (url.startsWith(WebView.SCHEME_MAILTO)) {
      Log.i(LCAT, "Launching mailer for " + url);
      Intent mailer =
          Intent.createChooser(new Intent(Intent.ACTION_SENDTO, Uri.parse(url)), "Send Message");
      webView.getProxy().getTiContext().getActivity().startActivity(mailer);
      return true;
    } else if (url.startsWith(WebView.SCHEME_GEO)) {
      Log.i(LCAT, "Launching app for " + url);
      /*geo:latitude,longitude
      geo:latitude,longitude?z=zoom
      geo:0,0?q=my+street+address
      geo:0,0?q=business+near+city
      */
      Intent geoviewer =
          Intent.createChooser(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), "Choose Viewer");
      webView.getProxy().getTiContext().getActivity().startActivity(geoviewer);
      return true;
    } else {
      String extension = MimeTypeMap.getFileExtensionFromUrl(url);
      String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
      if (mimeType != null) {
        return shouldHandleMimeType(mimeType, url);
      }

      if (DBG) {
        Log.e(LCAT, "NEED to Handle " + url);
      }
      return super.shouldOverrideUrlLoading(view, url);
    }
  }
コード例 #2
0
  @Override
  public boolean shouldOverrideUrlLoading(final WebView view, String url) {
    if (DBG) {
      Log.d(LCAT, "url=" + url);
    }

    if (URLUtil.isAssetUrl(url) || URLUtil.isContentUrl(url) || URLUtil.isFileUrl(url)) {
      TitaniumWebView twv = (TitaniumWebView) view;
      twv.loadFromSource(url, null);
      return true;
    } else if (URLUtil.isNetworkUrl(url)) {
      Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      view.getContext().startActivity(i);
      return true;
    } else {
      if (DBG) {
        Log.e(LCAT, "NEED to Handle " + url);
      }
    }

    return false;
  }