android上的嵌入式http服务器到服务器资产文件夹
我正在使用以下示例中的嵌入式http服务器 http服务器代码按以下方式启动:android上的嵌入式http服务器到服务器资产文件夹,android,android-webview,Android,Android Webview,我正在使用以下示例中的嵌入式http服务器 http服务器代码按以下方式启动: File filesDir = getFilesDir(); HttpServer server = new HttpServer(); server.addRequestHandler(new HttpStaticFileHandler(new File("."))); server.addRequestHandler(new HttpStaticFileHandler(filesDir)); server.b
File filesDir = getFilesDir();
HttpServer server = new HttpServer();
server.addRequestHandler(new HttpStaticFileHandler(new File(".")));
server.addRequestHandler(new HttpStaticFileHandler(filesDir));
server.bind(8081);
// Start the server thread
server.start();
嵌入http服务器,以便作为http://localhost:8081/folderpath/index.html
。然后,我将使用WebView访问localhost url
在webview中,我尝试访问
myWebView.loadUrl("`http://localhost:8081/`");
myWebView.loadUrl("`http://localhost:8081/index.html`");
myWebView.loadUrl("`http://localhost:8081/www/index.html`");
myWebView.loadUrl("`http://localhost:8081/assets/www/index.html`");
但它们都不起作用。对于需要从运行在android上的localhost为资产/www flder提供服务的情况,可能的解决方案是什么。谢谢。Android
资产
文件夹无法通过getFilesDir()
:getFilesDir()
返回其他目录。要为资产文件夹中的资源提供服务,您需要使用AssetManager
(),并将请求路径转换为适当的资源