android.webkit.WebView.getContext()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中android.webkit.WebView.getContext()方法的一些代码示例,展示了WebView.getContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.getContext()方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:getContext

WebView.getContext介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

webView.setWebViewClient(new WebViewClient(){
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url != null && url.startsWith("http://")) {
      view.getContext().startActivity(
        new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
      return true;
    } else {
      return false;
    }
  }
});

代码示例来源:origin: stackoverflow.com

public boolean shouldOverrideUrlLoading(WebView view, String url) {
  if (url != null && url.startsWith("market://")) {
    view.getContext().startActivity(
      new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    return true;
  } else {
    return false;
  }
}

代码示例来源:origin: pockethub/PocketHub

@Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (URL_PAGE.equals(url)) {
      view.loadUrl(url);
      return false;
    } else {
      UriLauncherActivity.launchUri(view.getContext(), Uri.parse(url));
      return true;
    }
  }
};

代码示例来源:origin: lzyzsd/JsBridge

/**
 * 这里只是加载lib包中assets中的 WebViewJavascriptBridge.js
 * @param view webview
 * @param path 路径
 */
public static void webViewLoadLocalJs(WebView view, String path){
  String jsContent = assetFile2Str(view.getContext(), path);
  view.loadUrl("javascript:" + jsContent);
}

代码示例来源:origin: stackoverflow.com

webview.setWebViewClient(new WebViewClient(){
   public boolean shouldOverrideUrlLoading(WebView view, String url) {
     String url2="http://www.playbuzz.org/";
      // all links  with in ur site will be open inside the webview 
      //links that start ur domain example(http://www.example.com/)
     if (url != null && url.startsWith(url2)){
       return false;
       } 
     // all links that points outside the site will be open in a normal android browser
    else  {
       view.getContext().startActivity(
       new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
       return true;
       }
   }
 });

代码示例来源:origin: Justson/AgentWeb

@Override
public void onJsAlert(WebView view, String url, String message) {
  AgentWebUtils.toastShowShort(view.getContext().getApplicationContext(), message);
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

@Override
  public void run() {
    if(ProxyUtils.setProxy(webView, "127.0.0.1", SysApplication.proxyPort)){
      Log.e("~~~~", "initProxyWebView()");
      webView.loadUrl(urlText.getText() + "");
      isSetProxy = true;
    }else{
      Toast.makeText(webView.getContext(),"Set proxy fail!",Toast.LENGTH_LONG).show();
    }
  }
});

代码示例来源:origin: androidquery/androidquery

private void setup(){
  
  String source = getSource(wv.getContext());
  String html = source.replace("@src", url).replace("@color", Integer.toHexString(color));
  
  wv.setWebViewClient(this);
  
  //wv.setInitialScale(100);
  wv.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
  wv.setBackgroundColor(color);
  
}

代码示例来源:origin: k9mail/k-9

@Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
  Uri uri = Uri.parse(url);
  if (CID_SCHEME.equals(uri.getScheme())) {
    return false;
  }
  Context context = webView.getContext();
  Intent intent = createBrowserViewIntent(uri, context);
  addActivityFlags(intent);
  boolean overridingUrlLoading = false;
  try {
    context.startActivity(intent);
    overridingUrlLoading = true;
  } catch (ActivityNotFoundException ex) {
    // If no application can handle the URL, assume that the WebView can handle it.
  }
  return overridingUrlLoading;
}

代码示例来源:origin: Justson/AgentWeb

@Override
  public WebListenerManager setDownloader(WebView webView, DownloadListener downloadListener) {
    Class<?> clazz = null;
    Object mDefaultDownloadImpl$Extra = null;
    try {
      clazz = Class.forName("com.just.agentweb.download.DefaultDownloadImpl");
      mDefaultDownloadImpl$Extra =
          clazz.getDeclaredMethod("create", Activity.class, WebView.class,
              Class.forName("com.just.agentweb.download.DownloadListener"),
              Class.forName("com.just.agentweb.download.DownloadingListener"),
              PermissionInterceptor.class)
              .invoke(mDefaultDownloadImpl$Extra, (Activity) webView.getContext()
                  , webView, null, null, mAgentWeb.getPermissionInterceptor());

    } catch (Throwable ignore) {
      if (LogUtils.isDebug()) {
        ignore.printStackTrace();
      }
    }
    return super.setDownloader(webView, mDefaultDownloadImpl$Extra == null ? downloadListener : (DownloadListener) mDefaultDownloadImpl$Extra);
  }
}

代码示例来源:origin: ankidroid/Anki-Android

public String createInfoHtmlString() {
  int textColorInt = Themes.getColorFromAttr(mWebView.getContext(), android.R.attr.textColor);
  String textColor = String.format("#%06X", (0xFFFFFF & textColorInt)); // Color to hex string
  String css = "<style>\n" +
      "h1, h3 { margin-bottom: 0; margin-top: 1em; text-transform: capitalize; }\n" +
      ".pielabel { text-align:center; padding:0px; color:white; }\n" +
      "body {color:" + textColor + ";}\n" +
      "</style>";
  StringBuilder stringBuilder = new StringBuilder();
  stringBuilder.append("<center>");
  stringBuilder.append(css);
  appendTodaysStats(stringBuilder);
  appendOverViewStats(stringBuilder);
  stringBuilder.append("</center>");
  return stringBuilder.toString();
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

@SuppressLint("NewApi")
@SuppressWarnings("all")
private static boolean setProxyKK(WebView webView, String host, int port, String applicationClassName) {
  Context appContext = webView.getContext().getApplicationContext();
  if (null == host) {
    System.clearProperty("http.proxyHost");

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

Log.e(LOG_TAG, "failed to get getInstance method");
  network = getInstanceMethod.invoke(networkClass, new Object[]{webView.getContext()});
} catch (Exception ex) {
  Log.e(LOG_TAG, "error getting network: " + ex);

代码示例来源:origin: TheFinestArtist/FinestWebView-Android

intent.setDataAndType(Uri.parse(url), "video/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
view.getContext().startActivity(intent);
// If we return true, onPageStarted, onPageFinished won't be called.
return true;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
view.getContext().startActivity(intent);
return true; // If we return true, onPageStarted, onPageFinished won't be called.

代码示例来源:origin: ankidroid/Anki-Android

@Override
  protected void onPostExecute(String html) {
    if (html != null && mIsRunning) {
      try {
        mWebView.loadData(URLEncoder.encode(html, "UTF-8").replaceAll("\\+", " "), "text/html; charset=utf-8", "utf-8");
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }
      mProgressBar.setVisibility(View.GONE);
      int backgroundColor = Themes.getColorFromAttr(mWebView.getContext(), android.R.attr.colorBackground);
      mWebView.setBackgroundColor(backgroundColor);
      mWebView.setVisibility(View.VISIBLE);
      mWebView.invalidate();
    }
  }
}

代码示例来源:origin: k9mail/k-9

protected WebResourceResponse shouldInterceptRequest(WebView webView, Uri uri) {
  if (!CID_SCHEME.equals(uri.getScheme())) {
    return RESULT_DO_NOT_INTERCEPT;
  }
  if (attachmentResolver == null) {
    return RESULT_DUMMY_RESPONSE;
  }
  String cid = uri.getSchemeSpecificPart();
  if (TextUtils.isEmpty(cid)) {
    return RESULT_DUMMY_RESPONSE;
  }
  Uri attachmentUri = attachmentResolver.getAttachmentUriForContentId(cid);
  if (attachmentUri == null) {
    return RESULT_DUMMY_RESPONSE;
  }
  Context context = webView.getContext();
  ContentResolver contentResolver = context.getContentResolver();
  try {
    String mimeType = contentResolver.getType(attachmentUri);
    InputStream inputStream = contentResolver.openInputStream(attachmentUri);
    WebResourceResponse webResourceResponse = new WebResourceResponse(mimeType, null, inputStream);
    addCacheControlHeader(webResourceResponse);
    return webResourceResponse;
  } catch (Exception e) {
    Timber.e(e, "Error while intercepting URI: %s", uri);
    return RESULT_DUMMY_RESPONSE;
  }
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

public static boolean setProxy(WebView webview, String host, int port) {
  int sdkInt = Build.VERSION.SDK_INT;
  if (sdkInt < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    return setProxyPreICS(webview, host, port);
  } else if (sdkInt < Build.VERSION_CODES.JELLY_BEAN) {
    return setProxyICS(webview, host, port);
  } else if (sdkInt < Build.VERSION_CODES.KITKAT) {
    return setProxyJB(webview, host, port);
  } else if (sdkInt < Build.VERSION_CODES.LOLLIPOP) {
    return setProxyKK(webview, host, port, "android.app.Application");
  } else {
    return webview != null && setProxyLollipop(webview.getContext(), host, port);
  }
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

public static boolean clearProxy(WebView webView) {
  int sdkInt = Build.VERSION.SDK_INT;
  if (sdkInt < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    return setProxyPreICS(webView, null, 0);
  } else if (sdkInt < Build.VERSION_CODES.JELLY_BEAN) {
    return setProxyICS(webView, null, 0);
  } else if (sdkInt < Build.VERSION_CODES.KITKAT) {
    return setProxyJB(webView, null, 0);
  } else if (sdkInt < Build.VERSION_CODES.LOLLIPOP) {
    return setProxyKK(webView, null, 0, "android.app.Application");
  } else {
    return setProxyLollipop(webView.getContext(), null, 0);
  }
}

代码示例来源:origin: androidquery/androidquery

fixWebviewTip(wv.getContext());

代码示例来源:origin: Justson/AgentWeb

mWebSettings.setBuiltInZoomControls(false);
mWebSettings.setSavePassword(false);
if (AgentWebUtils.checkNetwork(webView.getContext())) {
mWebSettings.setGeolocationEnabled(true);
String dir = AgentWebConfig.getCachePath(webView.getContext());
LogUtils.i(TAG, "dir:" + dir + "   appcache:" + AgentWebConfig.getCachePath(webView.getContext()));

相关文章

WebView类方法