需要android建议的phonegap自定义插件
嗨,我在移动应用程序 我已经在phonegap(html5、JQuery、JS)中开发了一个应用程序,我想开发一个插件来打印到BT打印机上 我下载打印机制造商的SDK,并通过以下方式将相应的.jar文件导入到我的项目中: 要将此库包含到项目中,请执行以下操作:需要android建议的phonegap自定义插件,android,plugins,cordova,Android,Plugins,Cordova,嗨,我在移动应用程序 我已经在phonegap(html5、JQuery、JS)中开发了一个应用程序,我想开发一个插件来打印到BT打印机上 我下载打印机制造商的SDK,并通过以下方式将相应的.jar文件导入到我的项目中: 要将此库包含到项目中,请执行以下操作: 将适当的库文件从SDK包拖到Project Explorer中 在项目文件夹上单击鼠标右键,然后选择“属性” 单击Java构建路径 单击库并单击添加JAR按钮 在主代码的顶部添加: 导入com.starmicronics.stario.S
port = StarIOPort.getPort(portName, portSettings, 10000, context);
我得到错误:状态=2消息=未找到类
我哪里错了???您是否将printer.jar文件添加到phonegap项目?是的,我已按照制造商的建议将.jar添加到项目中…确保printer.jar位于libs文件夹中,以便自动添加到Android应用程序中。
package com.tricedesigns;
import com.starmicronics.stario.StarIOPort;
import com.starmicronics.stario.StarIOPortException;
import com.starmicronics.stario.StarPrinterStatus;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.util.Log;
public class HelloPlugin extends Plugin {
public static final String NATIVE_ACTION_STRING="nativeAction";
public static final String SUCCESS_PARAMETER="success";
public static final String portName = "BT:";
public static final String portSettings = "mini";
@Override
public PluginResult execute(String action, JSONArray data, String callbackId) {
Log.d("HelloPlugin", "Hello, this is a native function called from PhoneGap/Cordova!");
//only perform the action if it is the one that should be invoked
if (NATIVE_ACTION_STRING.equals(action)) {
String resultType = null;
try {
resultType = data.getString(0);
}
catch (Exception ex) {
Log.d("HelloPlugin", ex.toString());
}
byte[] texttoprint = resultType.toString().getBytes();
if (resultType.equals(SUCCESS_PARAMETER)) {
StarIOPort port = null;
return new PluginResult(PluginResult.Status.OK, "Yay, Success!!!");
}
else {
return new PluginResult(PluginResult.Status.ERROR, "Oops, Error :(");
}
}
return null;
}
}
port = StarIOPort.getPort(portName, portSettings, 10000, context);