1
我開發了一個電話應用程序(HTML5,JQuery,JS),我想開發一個插件打印到BT打印機。android phonegap自定義插件問題沒有迴應
我下載了打印機制造商的SDK,並用我的項目中所需的所有方法將相應的.jar文件導入到了我的項目中。
爲了從JS打印機制造商SDK的JAVA方法中調用,我創建了下面的插件。
JS
var msgbox = function() {
};
msgbox.prototype.show = function(str, success, fail) {
PhoneGap.exec(success, fail, "msgbox", "show1", [str]);
};
navigator.msgbox = new msgbox();
JAVA
public class msgbox extends Plugin {
private static final String SHOW = "show";
private static final String SHOW1 = "show1";
private static final Context context = null;
private static final int MSG_INDEX = 0;
private String msg;
@Override
public PluginResult execute(String arg0, final JSONArray arg1, String arg2) {
if (arg0.equals(SHOW1))
{
StarIOPort port = null;
byte[] texttoprint = new byte[]{0x1b, 0x40, 0x1b,0x74,0x0D,(byte) 0x91,(byte) 0x92,(byte) 0x93,(byte) 0x94,(byte) 0x95,(byte) 0x96,(byte) 0x97,(byte) 0x98,(byte) 0x99,0x0A,0x0A,0x0A,0x0A,0x0A};
try
{
port = StarIOPort.getPort("BT:", "mini", 10000);
port.writePort(texttoprint, 0, texttoprint.length);
}
catch (StarIOPortException e)
{
Builder dialog = new AlertDialog.Builder(ctx);
dialog.setNegativeButton("Ok", null);
AlertDialog alert = dialog.create();
alert.setTitle("Failure");
alert.setMessage("Failed to connect to printer");
alert.show();
}
finally
{
if(port != null)
{
try
{
StarIOPort.releasePort(port);
} catch (StarIOPortException e) {}
}
}
}
return new PluginResult(Status.OK);
}
}
當我跑我沒有收到任何錯誤的項目,我沒有收到任何警報,我不打印到打印機。
我錯過了什麼?