Interprocess communication on Android

I am trying to develop an Android app that reads the loaded HTML content in a web browser (another background app).

Getting idea from chrome remote debug , it forwards tcp connections on specific port to UNIX domain

adb forward tcp: 9222 localabstract: webview_devtools_remote_ "process_id"

I tried to contact webview_devtools_remote_pid using LocalSocket as

    //https://developer.chrome.com/devtools/docs/protocol/1.1/page#command-enable
    JSONObject jo = new JSONObject();
    jo.put("id", 1);
    jo.put("method", "Page.enable");
    LocalSocket s = new LocalSocket();
    try {
        s.connect(new LocalSocketAddress("webview_devtools_remote_<p_id>"));
        OutputStream oss = s.getOutputStream();
        oss.write(jo.toString().getBytes("utf-8"));
        InputStream iss = s.getInputStream();
        Integer i;
        String res = "";
        while((i = iss.read()) != -1) {
            res += i.toString();
        }
    } catch (Exception e) {
        Log.e("Error", e.toString());
    }

      

but getting the connection dropped by the peer every time.

EDIT: Sometimes getting java.io.IOException: Broken pipe

Any ideas on this issue.

Is there some other easier way to do this?

+3


source to share


1 answer


I am assuming you are trying to connect to remote web socket debugging from an application that is running on the same device? This is only possible if your application is running as "root" or "shell user", or if it is signed with the same key as the application you are connecting to, see the code .



Once you solve this, you will need to adhere to the DevTools remote debugging protocol to navigate to the content of the HTML page, see the list of existing remote debug clients and libraries .

0


source







All Articles