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


Java CordovaResourceApi.openForRead方法代码示例

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


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

示例1: shouldInterceptRequest

import org.apache.cordova.CordovaResourceApi; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = parentEngine.resourceApi;
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
开发者ID:Andy-Ta,项目名称:COB,代码行数:32,代码来源:SystemWebViewClient.java

示例2: shouldInterceptRequest

import org.apache.cordova.CordovaResourceApi; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
  try {
    // Check the against the whitelist and lock out access to the WebView directory
    // Changing this will cause problems for your application
    if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
      LOG.w(TAG, "URL blocked by whitelist: " + url);
      // Results in a 404.
      return new WebResourceResponse("text/plain", "UTF-8", null);
    }

    CordovaResourceApi resourceApi = parentEngine.resourceApi;
    Uri origUri = Uri.parse(url);
    // Allow plugins to intercept WebView requests.
    Uri remappedUri = resourceApi.remapUri(origUri);

    if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
      CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
      return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
    }
    // If we don't need to special-case the request, let the browser load it.
    return null;
  } catch (IOException e) {
    if (!(e instanceof FileNotFoundException)) {
      LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
    }
    // Results in a 404.
    return new WebResourceResponse("text/plain", "UTF-8", null);
  }
}
 
开发者ID:zsxsoft,项目名称:cordova-plugin-x5-tbs,代码行数:32,代码来源:X5WebViewClient.java


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