我在移动应用程序中,我想打印到明星蓝牙打印机。Star 有一个 SDK,其中包含一个名为 StarIOPort3.1.jar 的 .jar 库,它负责打开/关闭打印机端口、获取状态以及将打印作业发送到打印机。
Star SDK 也有一个演示应用程序,具有打印机的所有功能。
在这个演示应用程序中,打印功能如下
public void ShowTextFormating(View view)
{
EditText portNameField = (EditText)findViewById(R.id.editText_PortName);
portName = portNameField.getText().toString();
CheckBox portSettingsCheckBox = (CheckBox)findViewById(R.id.checkBox_PortablePrinter);
portSettings = "";
if(portSettingsCheckBox.isChecked() == true)
{
portSettings = "mini";
}
if(portSettingsCheckBox.isChecked() == true)
{
Intent myIntent = new Intent(this, textFormatingMiniActivity.class);
startActivityFromChild(this, myIntent, 0);
}
else
{
Intent myIntent = new Intent(this, textFormatingActivity.class);
startActivityFromChild(this, myIntent, 0);
}
}
如果选中便携式打印机复选框,则调用 textFormatingMiniActivity.class。
textFormatingMiniActivity.class 如下
package com.StarMicronics.StarIOSDK;
import com.StarMicronics.StarIOSDK.PrinterFunctions.Alignment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class textFormatingMiniActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mini_textformating);
Spinner spinner_height = (Spinner)findViewById(R.id.spinner_height);
SpinnerAdapter ad = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new String[] {"1", "2", "3", "4", "5", "6", "7", "8"});
spinner_height.setAdapter(ad);
Spinner spinner_width = (Spinner)findViewById(R.id.spinner_width);
ad = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new String[] {"1", "2", "3", "4", "5", "6", "7", "8"});
spinner_width.setAdapter(ad);
Spinner spinner_alignment = (Spinner)findViewById(R.id.spinner_alignment);
ad = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new String[] {"Left", "Center", "Right"});
spinner_alignment.setAdapter(ad);
}
public void PrintText(View view)
{
String portName = StarIOSDKActivity.getPortName();
String portSettings = StarIOSDKActivity.getPortSettings();
CheckBox checkbox_underline = (CheckBox)findViewById(R.id.checkbox_underline);
boolean underline = checkbox_underline.isChecked();
CheckBox checkbox_emphasized = (CheckBox)findViewById(R.id.checkbox_emphasized);
boolean emphasized = checkbox_emphasized.isChecked();
CheckBox checkbox_upsidedown = (CheckBox)findViewById(R.id.chechbox_upsidedown);
boolean upsidedown = checkbox_upsidedown.isChecked();
CheckBox checkbox_invertColor = (CheckBox)findViewById(R.id.checkbox_invertcolor);
boolean invertColor = checkbox_invertColor.isChecked();
Spinner spinner_height = (Spinner)findViewById(R.id.spinner_height);
byte height = (byte) spinner_height.getSelectedItemPosition();
Spinner spinner_width = (Spinner)findViewById(R.id.spinner_width);
byte width = (byte) spinner_width.getSelectedItemPosition();
EditText edittext_leftmargin = (EditText)findViewById(R.id.edittext_leftmargin);
int leftMargin = 0;
try
{
leftMargin = Integer.parseInt(edittext_leftmargin.getText().toString());
}
catch(Exception e)
{
leftMargin = 0;
}
Spinner spinner_alignment = (Spinner)findViewById(R.id.spinner_alignment);
PrinterFunctions.Alignment alignment = PrinterFunctions.Alignment.Left;
switch(spinner_alignment.getSelectedItemPosition())
{
case 0:
alignment = Alignment.Left;
break;
case 1:
alignment = Alignment.Center;
break;
case 2:
alignment = Alignment.Right;
}
EditText edittext_texttoprint = (EditText)findViewById(R.id.editText_TextToPrint);
byte[] texttoprint = edittext_texttoprint.getText().toString().getBytes();
MiniPrinterFunctions.PrintText(this, portName, portSettings, underline, emphasized, upsidedown, invertColor, height, width, leftMargin, alignment, texttoprint);
}
这是我的问题:
如何从 jquery 调用 MiniPrinterFunctions.PrintText 因为我的应用程序是用 Jquery 编写的...
有没有其他方法可以使用上面的代码从 jquery 打印到这台打印机
请帮忙
提前谢谢