从我的Android应用程序发送/接收消息到Chrome



我正在尝试在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.0rn");
        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中的页面加载。

Chrome不允许每个应用程序连接到DevTool套接字。它确保连接应用程序与相同的密钥签名,或者用户是 root shell 。可以在此处找到此安全逻辑的源代码。

如果安全检查失败,则打印以下消息,您应该在logcat中看到它:

devtools:

的连接尝试

最新更新