當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。