1
我将JS代码加载到WebView
中。这JS代码请求使用file:
scheme uri的一些文件。这些文件被加密存储,我想在Java代码内及时解密它们JS模块请求它们。我知道如果这些请求将通过http:
方案,那么我可以设置本地http服务器并通过它将解密内容传递给JS模块。有没有办法将解密的内容传递给JS模块使用file:
scheme uri?在WebView中拦截“file:”方案请求
我将JS代码加载到WebView
中。这JS代码请求使用file:
scheme uri的一些文件。这些文件被加密存储,我想在Java代码内及时解密它们JS模块请求它们。我知道如果这些请求将通过http:
方案,那么我可以设置本地http服务器并通过它将解密内容传递给JS模块。有没有办法将解密的内容传递给JS模块使用file:
scheme uri?在WebView中拦截“file:”方案请求
为shouldInterceptRequest(WebView view, WebResourceRequest request)
创建WebViewClient
子类使用一个代理,并将其连接到您的WebView
:
webview.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
if ("file".equals(request.getUrl.getScheme())) { // plus your other conditions, of course
String mimeType = ... // your mime type
String encoding = ... // your character encoding
...
InputStream data = ... // open stream to your decrypted file data
return new WebResourceResponse(mimeType, encoding, data);
} else {
return null; // tell WebView to handle it
}
}
});
在您需要的加密密钥最低,你有它。 – zaph
当然。我需要一种拦截请求的方法。 – Lingviston