基本上,对于 Windows 机器,您需要知道 IP 地址。 这是网络上其他设备用来联系它的地址。 如果您已经有一个开放的 TCP/IP 套接字,则已经知道此地址。
HTTP 是一种基于 TCP 的协议。 它就像您的 HTTP 套接字一样,默认情况下在端口 80 上监听连接。 根据文档,Wamp 的默认端口是端口 80。
从包含 Webview 的连接活动中(
在这里),您可以了解更多信息。
private WebView webview;
public void onCreate(Bundle savedInstanceState) {
[initialize stuff as needed ...]
this.webview = (WebView)findViewById(R.id.webview);
WebSettings settings = this.webview.getSettings();
settings.setJavaScriptEnabled(true);
this.webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i(TAG, "Processing webview url click...");
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
Log.i(TAG, "Finished loading URL: " +url);
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e(TAG, "Error: " + description);
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
alertDialog.setTitle("Error");
alertDialog.setMessage(description);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
});
}
然后,每当您想要将URL加载或重新加载到Web视图中时:
this.webview.loadUrl("http://ipaddress/");
其中ipaddress是您使用TCP套接字连接的IP地址。如果由于某些原因,您的Windows机器不在端口80上运行HTTP服务器(在Wamp内置的httpd.conf中可配置),您也可以在URL中指定端口(在此示例中为8080):
this.webview.loadUrl("http://ipaddress:8080/");