function printSocket(str,ip,port){
if (plus.os.name == "Android") {plus.nativeUI.showWaiting("正在打印中。。。");
var Socket = plus.android.importClass("java.net.Socket");
var socket;
var outputStream;
//解决高低版本兼容
var StrictMode = plus.android.importClass("android.os.StrictMode");
var Build = plus.android.importClass("android.os.Build");
if (Build.VERSION.SDK_INT > 9) {
var policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
try{
socket = new Socket(ip, port);
socket.setKeepAlive(true);
outputStream = socket.getOutputStream();
plus.android.importClass(outputStream);
var bytes = plus.android.invoke(str, 'getBytes', 'gbk');
outputStream.write(bytes);
outputStream.flush();
socket.shutdownOutput();
plus.nativeUI.closeWaiting();
}catch(e){
mui.toast("网络连接超时,请重新连接!")
//TODO handle the exception
plus.nativeUI.closeWaiting();
}
}
}