最近在有涉及到Android连接网络打印机,看了下国内很少有相关的资料。所以,就给出自己弄出来的一个DEMO。主要还是通过Socket连接。这里就不废话了,直接贴上代码已经有注释.
package com.example.send2print;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import android.app.Activity;
import android.content.Context;
import android.content.pm.FeatureInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.v4.text.TextUtilsCompat;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private Socket client;
private FileInputStream fileInputStream;
private BufferedInputStream bufferedInputStream;
private OutputStream outputStream;
private Button button;
private TextView text;
private EditText etIp, etPort;
int port=0;
private String serNo = "201409098833";
private String orderNo = "A005";
private String CardNo = "00000356";
private String patType = "会员卡";
private String Amount = "300.00";
private String state = "支付完成";
private String time = "2014-09-09";