简体   繁体   中英

connect android device with printer and print document

I am developing an app in which I want to integrate print feature.Is it possible to send file to printer(for any company or brand) from app and print it.

so far googled and found following code but no luck.

try {

        client = new Socket(ipAddress, port);

        // create a byte array to file
        byte[] mybytearray = new byte[(int) file.length()];

        fileInputStream = new FileInputStream(file);
        bufferedInputStream = new BufferedInputStream(fileInputStream);
        // read the file
        bufferedInputStream.read(mybytearray, 0, mybytearray.length);

        outputStream = client.getOutputStream();
        // write file to the output stream byte by byte
        outputStream.write(mybytearray, 0, mybytearray.length);
        outputStream.flush();
        bufferedInputStream.close();
        outputStream.close();
        client.close();

    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

Note: I do not want to use Google Cloud Print. Any help would be greatly appreciated. Thanks.

You might be able to use lpdspooler http://lpdspooler.sourceforge.net/ , that is, if the printer supports LPR/LPD. If you can give some more details about the environment (printer, etc).

You can't directly connect to a printer and print from Android, unless the printer is cloud enabled.

However, you can add the printer to your Google Cloud Print account and print to it using the APIs available.

Note though that the computer that the printer is attached to will need to be in for print jobs to be processed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM