2
我有这样的Web服务器类:嵌入式Web服务器NanoHTTPD响应服务方法不会被调用
private class WebServer extends NanoHTTPD {
public WebServer()
{
super(PORT);
Log.i("myTag", "THIS IS RUNNING2");
}
@Override
public Response serve(String uri, Method method, Map<String, String> header, Map<String, String> parameters, Map<String, String> files) {
Log.i("myTag", "THIS IS RUNNING3");
String answer = "";
try {
// Open file from SD Card
File root = Environment.getExternalStorageDirectory();
FileReader index = new FileReader(root.getAbsolutePath() + "/www/index.html");
BufferedReader reader = new BufferedReader(index);
String line = "";
while ((line = reader.readLine()) != null) {
answer += line;
}
reader.close();
} catch(IOException ioe) {
Log.w("httpd", answer);
}
return new NanoHTTPD.Response(answer);
}
}
,我在网上找到(http://devnote1.blogspot.com/2016/05/android-studio-nanohttpd.html)。我跟着教程到T.
我设置了3个日志,应该在logcat下的标签“myTag”中可见,我注意到serve()方法中的第三个日志不会被输出。在我的android studio中,serve方法有一条线贯穿它,工具提示表示:“覆盖'import fi.iki.elonen.NanoHTTPD'中的不推荐方法。任何人都可以帮我解决这个问题吗?
我是使用这种依赖性:
compile 'com.nanohttpd:nanohttpd-webserver:2.1.1'
当我去到浏览器中输入localhost:8080,它并没有给我一个“网站无法到达”的错误,所以我相信一些web服务器上的东西正在任何帮助表示赞赏。谢谢