How to connect a network printer over Android?

后端 未结 6 508
轮回少年
轮回少年 2020-12-08 05:54

I want to code an Android app, which will connect to a network printer with a specific IP address, and then make a printing.

For printing I know that I need to write

相关标签:
6条回答
  • 2020-12-08 05:57

    Well, you cant connect any devices directly as you will need the driver installed. there are 3rd party apps like Google Cloud print that works seamlessly with Android though.

    0 讨论(0)
  • 2020-12-08 05:59

    Just Add This Code After oncreate Method

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = 
            new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
    
    0 讨论(0)
  • 2020-12-08 06:09

    Any device connected to a network will communicate via their IP and Ports / sockets. The simplest way to connect via telnet or socket and write the data to their socket buffers.

    try 
        {
        Socket sock = new Socket("192.168.1.222", 9100);
        PrintWriter oStream = new PrintWriter(sock.getOutputStream());
            oStream.println("HI,test from Android Device");
            oStream.println("\n\n\n");
            oStream.close();
            sock.close(); 
        }
        catch (UnknownHostException e) 
        {
            e.printStackTrace();
        } 
        catch (IOException e) 
        { 
            e.printStackTrace();
        } 
    
    0 讨论(0)
  • 2020-12-08 06:10

    Try to use PrintManager: https://developer.android.com/training/printing/custom-docs

      private void doPrint() {
        // Get a PrintManager instance
        PrintManager printManager = (PrintManager) getActivity()
                .getSystemService(Context.PRINT_SERVICE);
    
        // Set job name, which will be displayed in the print queue
        String jobName = getActivity().getString(R.string.app_name) + " Document";
    
        // Start a print job, passing in a PrintDocumentAdapter implementation
        // to handle the generation of a print document
        printManager.print(jobName, new MyPrintDocumentAdapter(getActivity()),
                null); //
    }
    
    0 讨论(0)
  • 2020-12-08 06:13

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

    0 讨论(0)
  • 2020-12-08 06:13

    Star has an Android SDK which has port discovery. It'll find any of their wifi receipt printers on your network. http://starmicronics.com/support/SDKDocumentation.aspx

    0 讨论(0)
提交回复
热议问题