我正在尝试在我的 android 应用程序和 android 上的 chrome 之间建立连接。我正在使用 LocalSocket 进行套接字通信,如下所示:
JSONObject request = new JSONObject();
request.put("method", "Page.reload");
LocalSocket s = new LocalSocket();
try {
s.connect(new LocalSocketAddress("chrome_devtools_remote", LocalSocketAddress.Namespace.ABSTRACT));
Log.i("Chrome: ", "After local socket connect");
//StringBuilder request = new StringBuilder().append("GET /json HTTP/1.0\r\n");
OutputStream oss = s.getOutputStream();
byte[] buffer = jo.toString().getBytes("utf-8");
oss.write(buffer, 0, buffer.length);
Log.i("Chrome: ", "outbuf size " + Integer.toString(s.getSendBufferSize()));
InputStream iss = s.getInputStream();
Integer i;
String res = "";
while ((i = iss.read()) != -1) {
res += i.toString();
}
Log.i("Chrome: ", res);
} catch (Exception e) {
Log.e("Error", "Connecting Local Socket "+e.toString());
}
我能够在 Chrome 和我的应用程序之间建立连接,但我无法发送和接收消息以在 chrome 中自动加载页面。