我对android很新鲜,我正在开发pos系统的android应用程序。我已经测试了从制造商收到的POS(销售点)系统的android演示应用程序。我将它的库添加到我的android项目。但是打印机是不适用于我的应用,但该应用正常运行。
这是制造商打印机Activtity:
private class contentPrintThread extends Thread {
@Override
public void run() {
super.run();
setName("Content Print Thread");
try {
ThermalPrinter.start(PrinterActivity.this);
ThermalPrinter.reset();
ThermalPrinter.setAlgin(ThermalPrinter.ALGIN_LEFT);
ThermalPrinter.setLeftIndent(leftDistance);
ThermalPrinter.setLineSpace(lineDistance);
if (wordFont == 4) {
ThermalPrinter.setFontSize(2);
ThermalPrinter.enlargeFontSize(2, 2);
} else if (wordFont == 3) {
ThermalPrinter.setFontSize(1);
ThermalPrinter.enlargeFontSize(2, 2);
} else if (wordFont == 2) {
ThermalPrinter.setFontSize(2);
} else if (wordFont == 1) {
ThermalPrinter.setFontSize(1);
}
ThermalPrinter.setGray(printGray);
ThermalPrinter.addString("test123");
ThermalPrinter.printString();
ThermalPrinter.clearString();
ThermalPrinter.walkPaper(100);
} catch (Exception e) {
e.printStackTrace();
Result = e.toString();
if (Result.equals("com.telpo.tps550.api.printer.NoPaperException")) {
nopaper = true;
} else if (Result.equals("com.telpo.tps550.api.printer.OverHeatException")) {
handler.sendMessage(handler.obtainMessage(OVERHEAT, 1, 0, null));
} else {
handler.sendMessage(handler.obtainMessage(PRINTERR, 1, 0, null));
}
} finally {
handler.sendMessage(handler.obtainMessage(CANCELPROMPT, 1, 0, null));
if (nopaper) {
handler.sendMessage(handler.obtainMessage(NOPAPER, 1, 0, null));
nopaper = false;
return;
}
ThermalPrinter.stop(PrinterActivity.this);
Log.v(TAG, "The Print Progress End !!!");
if (isClose) {
finish();
}
}
}
}
private class MyHandler extends Handler {
@Override
public void handleMessage(Message msg) {
if (stop == true)
return;
switch (msg.what) {
case NOPAPER:
noPaperDlg();
break;
case LOWBATTERY:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(PrinterActivity.this);
alertDialog.setTitle(R.string.operation_result);
alertDialog.setMessage(getString(R.string.LowBattery));
alertDialog.setPositiveButton(getString(R.string.dlg_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
alertDialog.show();
break;
case PRINTVERSION:
dialog.dismiss();
if (msg.obj.equals("1")) {
textPrintVersion.setText(printVersion);
} else {
Toast.makeText(PrinterActivity.this, R.string.operation_fail, Toast.LENGTH_LONG).show();
}
break;
case PRINTBARCODE:
new barcodePrintThread().start();
break;
case PRINTQRCODE:
new qrcodePrintThread().start();
break;
case PRINTPAPERWALK:
new paperWalkPrintThread().start();
break;
case PRINTCONTENT:
Log.e("task","in printcontent case");
new contentPrintThread().start();
break;
case MAKER:
new MakerThread().start();
break;
case PRINTPICTURE:
new printPicture().start();
break;
case CANCELPROMPT:
if (progressDialog != null && !PrinterActivity.this.isFinishing()) {
progressDialog.dismiss();
progressDialog = null;
}
break;
case EXECUTECOMMAND:
new executeCommand().start();
break;
case OVERHEAT:
AlertDialog.Builder overHeatDialog = new AlertDialog.Builder(PrinterActivity.this);
overHeatDialog.setTitle(R.string.operation_result);
overHeatDialog.setMessage(getString(R.string.overTemp));
overHeatDialog.setPositiveButton(getString(R.string.dlg_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
overHeatDialog.show();
break;
default:
Toast.makeText(PrinterActivity.this, "Print Error!", Toast.LENGTH_LONG).show();
break;
}
}
}
*****这是打印按钮 -
buttonContentPrint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String exditText;
exditText = editTextLeftDistance.getText().toString();
if (exditText == null || exditText.length() < 1) {
Toast.makeText(PrinterActivity.this, getString(R.string.left_margin) + getString(R.string.lengthNotEnougth), Toast.LENGTH_LONG).show();
return;
}
leftDistance = Integer.parseInt(exditText);
exditText = editTextLineDistance.getText().toString();
if (exditText == null || exditText.length() < 1) {
Toast.makeText(PrinterActivity.this, getString(R.string.row_space) + getString(R.string.lengthNotEnougth), Toast.LENGTH_LONG).show();
return;
}
lineDistance = Integer.parseInt(exditText);
printContent = editTextContent.getText().toString();
exditText = editTextWordFont.getText().toString();
if (exditText == null || exditText.length() < 1) {
Toast.makeText(PrinterActivity.this, getString(R.string.font_size) + getString(R.string.lengthNotEnougth), Toast.LENGTH_LONG).show();
return;
}
wordFont = Integer.parseInt(exditText);
exditText = editTextPrintGray.getText().toString();
if (exditText == null || exditText.length() < 1) {
Toast.makeText(PrinterActivity.this, getString(R.string.gray_level) + getString(R.string.lengthNotEnougth), Toast.LENGTH_LONG).show();
return;
}
printGray = Integer.parseInt(exditText);
if (leftDistance > MAX_LEFT_DISTANCE) {
Toast.makeText(PrinterActivity.this, getString(R.string.outOfLeft), Toast.LENGTH_LONG).show();
return;
} else if (lineDistance > 255) {
Toast.makeText(PrinterActivity.this, getString(R.string.outOfLine), Toast.LENGTH_LONG).show();
return;
} else if (wordFont > 4 || wordFont < 1) {
Toast.makeText(PrinterActivity.this, getString(R.string.outOfFont), Toast.LENGTH_LONG).show();
return;
} else if (printGray < 0 || printGray > 12) {
Toast.makeText(PrinterActivity.this, getString(R.string.outOfGray), Toast.LENGTH_LONG).show();
return;
}
if (printContent == null || printContent.length() == 0) {
Toast.makeText(PrinterActivity.this, getString(R.string.empty), Toast.LENGTH_LONG).show();
return;
}
if (LowBattery == true) {
handler.sendMessage(handler.obtainMessage(LOWBATTERY, 1, 0, null));
} else {
if (!nopaper) {
setTitle("print character");
progressDialog = ProgressDialog.show(PrinterActivity.this, getString(R.string.bl_dy), getString(R.string.printing_wait));
handler.sendMessage(handler.obtainMessage(PRINTCONTENT, 1, 0, null));
// handler.sendMessage(handler.);
} else {
Toast.makeText(PrinterActivity.this, getString(R.string.ptintInit), Toast.LENGTH_LONG).show();
}
}
}
})
1.我可以在我的项目中添加制造商应用作为模块吗?
2.如何在我的应用程序中添加此代码,以及任何其他特殊方式来执行此操作
答案 0 :(得分:0)
在提供的SDK制作上有一个库文件夹,您将该Lib文件夹复制到您的项目 然后你复制它你右键单击lib文件夹,我假设你已经将它复制到app文件夹下右键单击libs文件夹,然后添加为库,它将被添加,现在你可以包含打印机Activity:到你的MainActivity,创建输入数据的表单,然后将该数据存入您的btnprint
如果您遇到任何问题,请不要犹豫,我已为tps390和tps550开发软件,您可以在Twitter上关注我@macfranci或Instagram
答案 1 :(得分:-1)
添加演示应用程序中的所有库以及jniLib,如此处jniLibs