我将 JS 代码加载到file:
。此 JS 代码使用http:
scheme uri请求一些文件。这些文件是加密存储的,我想及时在Java代码中解密它们 JS 模块请求它们。我知道如果这些请求是通过file:
方案,那么我可以设置本地http服务器并通过它将解密的内容传递给 JS 模块。有没有办法使用mysqli_real_escape_string()
方案uri将解密的内容传递给 JS 模块?
答案 0 :(得分:2)
创建WebViewClient
子类,并覆盖shouldInterceptRequest(WebView view, WebResourceRequest request)
,并将其附加到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
}
}
});