当前位置: 首页>>代码示例>>Java>>正文


Java WebView.getContext方法代码示例

本文整理汇总了Java中android.webkit.WebView.getContext方法的典型用法代码示例。如果您正苦于以下问题:Java WebView.getContext方法的具体用法?Java WebView.getContext怎么用?Java WebView.getContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.webkit.WebView的用法示例。


在下文中一共展示了WebView.getContext方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printOrCreatePdfFromWebview

import android.webkit.WebView; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@SuppressWarnings("deprecation")
public PrintJob printOrCreatePdfFromWebview(WebView webview, String jobName) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Context c = webview.getContext();
        PrintDocumentAdapter printAdapter;
        PrintManager printManager = (PrintManager) c.getSystemService(Context.PRINT_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            printAdapter = webview.createPrintDocumentAdapter(jobName);
        } else {
            printAdapter = webview.createPrintDocumentAdapter();
        }
        if (printManager != null) {
            return printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
        }
    } else {
        Log.e(getClass().getName(), "ERROR: Method called on too low Android API version");
    }
    return null;
}
 
开发者ID:gsantner,项目名称:markor,代码行数:21,代码来源:ShareUtilBase.java

示例2: handleIntentUrl

import android.webkit.WebView; //导入方法依赖的package包/类
private static boolean handleIntentUrl(WebView view, String url) {
    if (TextUtils.isEmpty(url) || !url.startsWith("intent://"))

        return false;
    try {
        Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
        ResolveInfo info = PackageUtil.getResolveInfo(view.getContext(), intent);
        if (info != null) {
            if (!(view.getContext() instanceof Activity))
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            view.getContext().startActivity(intent);
            return true;
        }
    } catch (URISyntaxException e) {
        Log.printStackTrace(e);
    }


    return false;
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:21,代码来源:WebModel.java

示例3: shouldOverrideUrlLoading

import android.webkit.WebView; //导入方法依赖的package包/类
@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;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:22,代码来源:K9WebViewClient.java

示例4: shouldInterceptRequest

import android.webkit.WebView; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:34,代码来源:K9WebViewClient.java

示例5: convertMarkupShowInWebView

import android.webkit.WebView; //导入方法依赖的package包/类
/**
 * Convert markup to target format and show the result in a WebView
 *
 * @param document The document containting the contents
 * @param webView  The WebView content to be shown in
 * @return Copy of converted html
 */
public String convertMarkupShowInWebView(Document document, WebView webView) {
    Context context = webView.getContext();
    String html = convertMarkup(document.getContent(), context);


    String baseFolder = new AppSettings(context).getNotebookDirectoryAsStr();
    if (document.getFile() != null && document.getFile().getParentFile() != null) {
        baseFolder = document.getFile().getParent();
    }
    baseFolder = "file://" + baseFolder + "/";
    webView.loadDataWithBaseURL(baseFolder, html, getContentType(), UTF_CHARSET, null);

    return html;
}
 
开发者ID:gsantner,项目名称:markor,代码行数:22,代码来源:TextConverter.java

示例6: shouldOverrideUrlLoading

import android.webkit.WebView; //导入方法依赖的package包/类
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url.startsWith("file://")) {
        ShareUtil su = new ShareUtil(view.getContext());
        url = url.replace("%20", " "); // Workaround for parser - cannot deal with spaces and have other entities problems
        File file = new File(url.replace("file://", ""));
        String mimetype;
        if (ContextUtils.get().isMaybeMarkdownFile(file)) {
            Intent newPreview = new Intent(_activity, DocumentActivity.class);
            newPreview.putExtra(DocumentIO.EXTRA_PATH, file);
            newPreview.putExtra(DocumentActivity.EXTRA_DO_PREVIEW, true);
            _activity.startActivity(newPreview);
        } else if ((mimetype = ContextUtils.getMimeType(url)) != null) {
            Intent intent = new Intent();
            intent.setAction(android.content.Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setDataAndType(su.getUriByFileProviderAuthority(file), mimetype);
            _activity.startActivity(intent);
        } else {
            Uri uri = Uri.parse(url);
            _activity.startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), _activity.getString(R.string.open_with)));
        }
    } else {
        ContextUtils.get().openWebpageInExternalBrowser(url);
    }
    return true;
}
 
开发者ID:gsantner,项目名称:markor,代码行数:28,代码来源:MarkorWebViewClient.java

示例7: WebViewer

import android.webkit.WebView; //导入方法依赖的package包/类
/**
 * Creates a new WebViewer component.
 *
 * @param container  container the component will be placed in
 */
public WebViewer(ComponentContainer container) {
  super(container);

  webview = new WebView(container.$context());
  resetWebViewClient();       // Set up the web view client
  webview.getSettings().setJavaScriptEnabled(true);
  webview.setFocusable(true);
  // adds a way to send strings to the javascript
  wvInterface = new WebViewInterface(webview.getContext());
  webview.addJavascriptInterface(wvInterface, "AppInventor");
  // enable pinch zooming and zoom controls
  webview.getSettings().setBuiltInZoomControls(true);

  if (SdkLevel.getLevel() >= SdkLevel.LEVEL_ECLAIR)
    EclairUtil.setupWebViewGeoLoc(this, webview, container.$context());

  container.$add(this);

  webview.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_UP:
          if (!v.hasFocus()) {
            v.requestFocus();
          }
          break;
      }
      return false;
    }
  });

  // set the initial default properties.  Height and Width
  // will be fill-parent, which will be the default for the web viewer.

  HomeUrl("");
  Width(LENGTH_FILL_PARENT);
  Height(LENGTH_FILL_PARENT);
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:46,代码来源:WebViewer.java

示例8: dispatchEvent

import android.webkit.WebView; //导入方法依赖的package包/类
private static void dispatchEvent(WebView webView, Event event) {
  ReactContext reactContext = (ReactContext) webView.getContext();
  EventDispatcher eventDispatcher =
    reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  eventDispatcher.dispatchEvent(event);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:7,代码来源:ReactWebViewManager.java


注:本文中的android.webkit.WebView.getContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。