我无法让 nanohttpd 工作。似乎无法www在应用程序的根目录中找到该目录。
我的代码在https://github.com/tlkahn/neonx
我在 MainActivity.java 的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navView = findViewById(R.id.nav_view);
mWebView = findViewById(R.id.webkit);
navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
WebSettings webSettings = mWebView.getSettings();
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
webSettings.setDomStorageEnabled(true);
mWebView.getSettings().setLoadsImagesAutomatically(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return false;
}
});
if (!haveNetworkConnection()) {
new AlertDialog.Builder(this)
.setTitle("You are not connected to internet.")
.setMessage("Are you sure you want to exit?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finishAffinity();
System.exit(0);
}
}).setNegativeButton("No", null).show();
}
startLocalServer(3000, "www", true, true );
}
当我尝试访问时localhost:3000,出现错误:给定路径不是目录。错误似乎来自这一行: https: //git.io/fjS3f
我猜我初始化 rootDir 的方式是错误的(这一行:https: //git.io/fjS3v)。但是我怎样才能使这项工作呢?我的意思是服务整个目录,这意味着所有 CSS/JS/hypyerlinks 应该工作,一旦 nanohttpd 开始服务......
吃鸡游戏
慕后森
相关分类