2017-07-24 59 views
1

我很新鮮android,我正在開發pos應用系統的android應用程序。我已經測試了從製造商收到的POS(銷售點)系統的android演示應用程序。我添加了它的庫到我的android項目。但打印機沒有爲我的應用程序工作,但該應用程序正常工作。如何添加打印機sdk POS系統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.can我可以在我的項目中添加製造商應用程序作爲模塊?

2.how在我的應用程序添加此代碼,以及其他特殊的方式來做到這一點

回答

0

在該處提供的SDK製作是一個庫文件夾,您複製lib文件夾到您的項目 然後在您複製它你去右鍵點擊lib文件夾,我假設你已經複製它下的應用程序文件夾右鍵單擊libs文件夾,然後添加爲庫,它會被添加,現在你可以包括打印機活動:到你的MainActivity,創建形式你輸入數據的惡意,然後錢包,數據到你的btnprint

如果你面對任何問題不要猶豫問,我已經開發軟件爲tps390和tps550你ca在twitter上關注我@macfranci或instagram

相關問題