Code example for LocalSocket

Methods: connectgetOutputStream

    private synchronized void openSocket() throws IOException { 
        LocalSocketAddress socketAddress =
                new LocalSocketAddress("/dev/socket/usbd", LocalSocketAddress.Namespace.FILESYSTEM);
        mSocket = new LocalSocket();
        mOutputStream = mSocket.getOutputStream();
    private void listenToSocket() throws IOException { 
        InputStream usbdInputStream = mSocket.getInputStream();
        byte[] buffer = new byte[100];
        while (true) { 
            int count =;
            if (count < 0) {
                throw new IOException("Unexpected end of stream");
Connect your IDE to all the code out there  Get Codota for Java