删 删 删
This commit is contained in:
parent
1a45602b31
commit
4b52c32260
@ -13,10 +13,6 @@
|
|||||||
|
|
||||||
<source-file src="src/android/cordova/plugin/jcprinter/JcPrinter.java"
|
<source-file src="src/android/cordova/plugin/jcprinter/JcPrinter.java"
|
||||||
target-dir="cordova/plugin/jcprinter"/>
|
target-dir="cordova/plugin/jcprinter"/>
|
||||||
<source-file src="src/android/cordova/plugin/jcprinter/Util.java"
|
|
||||||
target-dir="cordova/plugin/jcprinter"/>
|
|
||||||
<source-file src="src/android/cordova/plugin/jcprinter/MyApplication.java"
|
|
||||||
target-dir="cordova/plugin/jcprinter"/>
|
|
||||||
|
|
||||||
<lib-file src="src/android/3.1.8-release.aar" />
|
<lib-file src="src/android/3.1.8-release.aar" />
|
||||||
<lib-file src="src/android/image-2.0.10-release.aar" />
|
<lib-file src="src/android/image-2.0.10-release.aar" />
|
||||||
|
@ -3,36 +3,30 @@ package cordova.plugin.jcprinter;
|
|||||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import org.apache.cordova.CallbackContext;
|
import org.apache.cordova.CallbackContext;
|
||||||
import org.apache.cordova.CordovaPlugin;
|
import org.apache.cordova.CordovaPlugin;
|
||||||
import org.apache.cordova.PluginResult;
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
import com.gengcon.www.jcprintersdk.bean.ImageDataInfo;
|
import com.gengcon.www.jcprintersdk.JCPrintApi;
|
||||||
|
import com.gengcon.www.jcprintersdk.callback.Callback;
|
||||||
import com.gengcon.www.jcprintersdk.callback.PrintCallback;
|
import com.gengcon.www.jcprintersdk.callback.PrintCallback;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -42,42 +36,41 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
|
|
||||||
private static final String TAG = "JcPrinter";
|
private static final String TAG = "JcPrinter";
|
||||||
|
|
||||||
private Method[] methods = Util.getInstance().getClass().getDeclaredMethods();
|
private static JCPrintApi api;
|
||||||
|
|
||||||
/**
|
private final Method[] methods = JCPrintApi.class.getDeclaredMethods();
|
||||||
* 页打印份数
|
|
||||||
*/
|
|
||||||
private int quantity;
|
|
||||||
/**
|
|
||||||
* 是否打印错误
|
|
||||||
*/
|
|
||||||
private boolean isError;
|
|
||||||
/**
|
|
||||||
* 是否取消打印
|
|
||||||
*/
|
|
||||||
private boolean isCancel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印模式
|
|
||||||
*/
|
|
||||||
private int printMode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印浓度
|
|
||||||
*/
|
|
||||||
private int printDensity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印倍率(分辨率)
|
|
||||||
*/
|
|
||||||
private Float printMultiple;
|
|
||||||
|
|
||||||
private final static int START_PRINT = 1;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void pluginInitialize() {
|
protected void pluginInitialize() {
|
||||||
super.pluginInitialize();
|
super.pluginInitialize();
|
||||||
|
if(api == null){
|
||||||
|
api = JCPrintApi.getInstance(CALLBACK);
|
||||||
|
api.init(cordova.getActivity().getApplication());
|
||||||
|
api.initImageProcessingDefault("", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JCPrintApi getInstance() {
|
||||||
|
if (api == null) {
|
||||||
|
this.pluginInitialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
return api;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int openPrinter(String address) {
|
||||||
|
return getInstance().openPrinterByAddress(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
getInstance().close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int isConnection() {
|
||||||
|
return getInstance().isConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -102,7 +95,6 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
String methodName = args.optString(0);
|
String methodName = args.optString(0);
|
||||||
Log.d(TAG,"action-method:"+methodName);
|
Log.d(TAG,"action-method:"+methodName);
|
||||||
for(Method m:this.methods){
|
for(Method m:this.methods){
|
||||||
String name = m.getName();
|
|
||||||
if(m.getName().equals(methodName)){
|
if(m.getName().equals(methodName)){
|
||||||
try {
|
try {
|
||||||
JSONArray methodJsonArgs = args.getJSONArray(1);
|
JSONArray methodJsonArgs = args.getJSONArray(1);
|
||||||
@ -110,7 +102,7 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
for(int i=0;i<methodJsonArgs.length();i++){
|
for(int i=0;i<methodJsonArgs.length();i++){
|
||||||
Object obj = methodJsonArgs.opt(i);
|
Object obj = methodJsonArgs.opt(i);
|
||||||
if(obj instanceof JSONArray){
|
if(obj instanceof JSONArray){
|
||||||
Class a = m.getParameterTypes()[i].getComponentType();
|
Class<?> a = m.getParameterTypes()[i].getComponentType();
|
||||||
Object array = Array.newInstance(a,((JSONArray) obj).length());
|
Object array = Array.newInstance(a,((JSONArray) obj).length());
|
||||||
for(int j=0;j<((JSONArray) obj).length();j++){
|
for(int j=0;j<((JSONArray) obj).length();j++){
|
||||||
Array.set(array,j,((JSONArray) obj).opt(j));
|
Array.set(array,j,((JSONArray) obj).opt(j));
|
||||||
@ -120,7 +112,7 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
methodArgs[i] = obj;
|
methodArgs[i] = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.invoke(Util.getInstance(),methodArgs);
|
m.invoke(getInstance(),methodArgs);
|
||||||
callbackContext.success();
|
callbackContext.success();
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
callbackContext.error(e.getMessage());
|
callbackContext.error(e.getMessage());
|
||||||
@ -131,7 +123,7 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
|
|
||||||
|
|
||||||
case "generateLabelJson":
|
case "generateLabelJson":
|
||||||
callbackContext.success(new String(Util.getInstance().generateLabelJson()));
|
callbackContext.success(new String(getInstance().generateLabelJson()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
@ -141,6 +133,13 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//重置错误状态变量
|
||||||
|
private boolean isError = false;
|
||||||
|
//重置取消打印状态变量
|
||||||
|
private boolean isCancel = false;
|
||||||
|
|
||||||
|
private int generatedPrintDataPageCount = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打印标签
|
* 打印标签
|
||||||
*
|
*
|
||||||
@ -148,34 +147,37 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
private void print(JSONArray args, CallbackContext callbackContext) {
|
private void print(JSONArray args, CallbackContext callbackContext) {
|
||||||
JSONArray data = args.optJSONArray(0);
|
JSONArray data = args.optJSONArray(0);
|
||||||
String infoStr = args.optString(1);
|
String infoStr = args.optString(1);
|
||||||
List<String> info = new ArrayList<>();
|
JSONObject cfg = args.optJSONObject(2);
|
||||||
info.add(infoStr);
|
int printDensity = cfg.optInt("printDensity",8);
|
||||||
//重置错误状态变量
|
int printMode = cfg.optInt("printMode",2);
|
||||||
isError = false;
|
int paperType = cfg.optInt("paperType",2);
|
||||||
//重置取消打印状态变量
|
int quantity = cfg.optInt("quantity",1);
|
||||||
isCancel = false;
|
generatedPrintDataPageCount = 0;
|
||||||
//总打印份数
|
//总打印份数
|
||||||
|
|
||||||
final int[] generatedPrintDataPageCount = {0};
|
|
||||||
int pageCount = data.length();
|
int pageCount = data.length();
|
||||||
quantity = 1;
|
|
||||||
int totalQuantity = pageCount * quantity;
|
int totalQuantity = pageCount * quantity;
|
||||||
//总打印份数,表示所有页面的打印份数之和。例如,如果你有3页需要打印,第一页打印3份,第二页打印2份,第三页打印5份,那么count的值应为10(3+2+5)。
|
//总打印份数,表示所有页面的打印份数之和。例如,如果你有3页需要打印,第一页打印3份,第二页打印2份,第三页打印5份,那么count的值应为10(3+2+5)。
|
||||||
Util.getInstance().setTotalQuantityOfPrints(totalQuantity);
|
getInstance().setTotalQuantityOfPrints(totalQuantity);
|
||||||
printDensity = 8;
|
|
||||||
printMode = 2;
|
|
||||||
Log.d(TAG, "测试:参数设置-打印浓度: " + printDensity + ",打印模式:" + printMode);
|
Log.d(TAG, "测试:参数设置-打印浓度: " + printDensity + ",打印模式:" + printMode);
|
||||||
|
|
||||||
|
List<String>pageData = new ArrayList<>();
|
||||||
|
List<String>pageInfo = new ArrayList<>();
|
||||||
|
for(int i=0;i<data.length();i++){
|
||||||
|
pageData.add(data.optString(i));
|
||||||
|
pageInfo.add(infoStr);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 参数1:打印浓度 ,参数2:纸张类型 参数3:打印模式
|
* 参数1:打印浓度 ,参数2:纸张类型 参数3:打印模式
|
||||||
* 打印浓度 B50/B50W/T6/T7/T8 建议设置6或8,Z401/B32建议设置8,B3S/B21/B203/B1建议设置3
|
* 打印浓度 B50/B50W/T6/T7/T8 建议设置6或8,Z401/B32建议设置8,B3S/B21/B203/B1建议设置3
|
||||||
*/
|
*/
|
||||||
Util.getInstance().startPrintJob(printDensity, 2, printMode, new PrintCallback() {
|
getInstance().startPrintJob(printDensity, paperType, printMode, new PrintCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(int pageIndex, int quantityIndex, HashMap<String, Object> hashMap) {
|
public void onProgress(int pageIndex, int quantityIndex, HashMap<String, Object> hashMap) {
|
||||||
Log.d(TAG, "测试:打印进度:已打印到第" + pageIndex + "页,第" + quantityIndex + "份");
|
Log.d(TAG, "测试:打印进度:已打印到第" + pageIndex + "页,第" + quantityIndex + "份");
|
||||||
//打印进度回调
|
//打印进度回调
|
||||||
if (pageIndex == pageCount && quantityIndex == quantity) {
|
if (pageIndex == pageCount && quantityIndex == quantity) {
|
||||||
if (Util.getInstance().endJob()) {
|
if (getInstance().endJob()) {
|
||||||
Log.d(TAG, "结束打印成功");
|
Log.d(TAG, "结束打印成功");
|
||||||
callbackContext.success("结束打印成功");
|
callbackContext.success("结束打印成功");
|
||||||
} else {
|
} else {
|
||||||
@ -317,69 +319,77 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
if (pageIndex > pageCount) {
|
if (pageIndex > pageCount) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String>pageData = new ArrayList<>();
|
|
||||||
String dataStr= data.optString(pageIndex-1);
|
if(generatedPrintDataPageCount < pageCount){
|
||||||
pageData.add(dataStr);
|
if(pageCount - generatedPrintDataPageCount <bufferSize){
|
||||||
Util.getInstance().commitData(pageData,info);
|
getInstance().commitData(pageData.subList(generatedPrintDataPageCount,pageCount),pageInfo.subList(generatedPrintDataPageCount,pageCount));
|
||||||
|
generatedPrintDataPageCount += pageCount;
|
||||||
|
} else {
|
||||||
|
getInstance().commitData(
|
||||||
|
pageData.subList(generatedPrintDataPageCount,
|
||||||
|
generatedPrintDataPageCount + bufferSize),
|
||||||
|
pageInfo.subList(generatedPrintDataPageCount,
|
||||||
|
generatedPrintDataPageCount + bufferSize));
|
||||||
|
generatedPrintDataPageCount += bufferSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void isConnection(CallbackContext callbackContext) throws JSONException {
|
private void isConnection(CallbackContext callbackContext) {
|
||||||
int connectFlag = Util.isConnection();
|
int connectFlag = isConnection();
|
||||||
cordova.getActivity().runOnUiThread(() -> {
|
cordova.getActivity().runOnUiThread(() -> {
|
||||||
String hint = "";
|
|
||||||
switch (connectFlag) {
|
switch (connectFlag) {
|
||||||
case 0:
|
case 0:
|
||||||
hint = "已连接";
|
callbackContext.success(this.msg(connectFlag,"已连接"));
|
||||||
callbackContext.success(hint);
|
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
hint = "未连接";
|
callbackContext.error(this.msg(connectFlag,"未连接"));
|
||||||
callbackContext.error(hint);
|
|
||||||
break;
|
break;
|
||||||
case -3:
|
case -3:
|
||||||
hint = "不支持的机型";
|
callbackContext.error(this.msg(connectFlag,"不支持的机型"));
|
||||||
callbackContext.error(hint);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
callbackContext.error(this.msg(connectFlag,"未知状态"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JSONObject msg(int code,String msg) {
|
||||||
|
try {
|
||||||
|
return new JSONObject().put("code",code).put("msg",msg);
|
||||||
|
}catch (JSONException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void connectPrinter(JSONArray args, CallbackContext callbackContext) throws JSONException {
|
private void connectPrinter(JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||||
JSONObject obj = args.getJSONObject(0);
|
JSONObject obj = args.getJSONObject(0);
|
||||||
String address = obj.getString("address");
|
String address = obj.getString("address");
|
||||||
int connectResult = Util.openPrinter(address);
|
int connectFlag = openPrinter(address);
|
||||||
cordova.getActivity().runOnUiThread(() -> {
|
cordova.getActivity().runOnUiThread(() -> {
|
||||||
String hint = "";
|
switch (connectFlag) {
|
||||||
switch (connectResult) {
|
|
||||||
case 0:
|
case 0:
|
||||||
hint = "连接成功";
|
callbackContext.success(this.msg(connectFlag,"连接成功"));
|
||||||
callbackContext.success(hint);
|
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
hint = "连接失败";
|
callbackContext.error(this.msg(connectFlag,"连接失败"));
|
||||||
callbackContext.error(hint);
|
|
||||||
break;
|
break;
|
||||||
case -2:
|
case -3:
|
||||||
hint = "不支持的机型";
|
callbackContext.error(this.msg(connectFlag,"不支持的机型"));
|
||||||
callbackContext.error(hint);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
callbackContext.error(this.msg(connectFlag,"未知状态"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
private void getList(CallbackContext callbackContext) {
|
||||||
* Find Zebra printers we can connect to
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
private JSONArray getList(CallbackContext callbackContext) {
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
int blueTooth_permission = ContextCompat.checkSelfPermission(cordova.getContext(), Manifest.permission.BLUETOOTH);
|
int blueTooth_permission = ContextCompat.checkSelfPermission(cordova.getContext(), Manifest.permission.BLUETOOTH);
|
||||||
@ -424,8 +434,53 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
Log.d(TAG,"printers = " + printers);
|
Log.d(TAG,"printers = " + printers);
|
||||||
callbackContext.success(printers);
|
callbackContext.success(printers);
|
||||||
return printers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Callback CALLBACK = new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onConnectSuccess(String s) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisConnect() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onElectricityChange(int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCoverStatus(int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPaperStatus(int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRfidReadStatus(int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPrinterIsFree(int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHeartDisConnect() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFirmErrors() {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package cordova.plugin.jcprinter;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义Application
|
|
||||||
*
|
|
||||||
* @author zhangbin
|
|
||||||
*/
|
|
||||||
public class MyApplication extends Application {
|
|
||||||
private static MyApplication app;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
app = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MyApplication getInstance() {
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
package cordova.plugin.jcprinter;
|
|
||||||
|
|
||||||
import com.gengcon.www.jcprintersdk.JCPrintApi;
|
|
||||||
import com.gengcon.www.jcprintersdk.callback.Callback;
|
|
||||||
import cordova.plugin.jcprinter.MyApplication;
|
|
||||||
|
|
||||||
public class Util {
|
|
||||||
|
|
||||||
|
|
||||||
private static final Callback CALLBACK = new Callback() {
|
|
||||||
@Override
|
|
||||||
public void onConnectSuccess(String s) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisConnect() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onElectricityChange(int i) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCoverStatus(int i) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPaperStatus(int i) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRfidReadStatus(int i) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrinterIsFree(int i) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onHeartDisConnect() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFirmErrors() {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static JCPrintApi api;
|
|
||||||
|
|
||||||
|
|
||||||
public static JCPrintApi getInstance() {
|
|
||||||
if (api == null) {
|
|
||||||
api = JCPrintApi.getInstance(CALLBACK);
|
|
||||||
api.init(MyApplication.getInstance());
|
|
||||||
api.initImageProcessingDefault("", "");
|
|
||||||
|
|
||||||
|
|
||||||
// Log.d(TAG, "api.init"+api.init(MyApplication.getInstance()));
|
|
||||||
// Log.d(TAG, "api.initImageProcessingDefault"+ api.initImageProcessingDefault("", ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
return api;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String TAG = "PrintUtil";
|
|
||||||
|
|
||||||
public static int openPrinter(String address) {
|
|
||||||
getInstance();
|
|
||||||
return api.openPrinterByAddress(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void close() {
|
|
||||||
getInstance();
|
|
||||||
api.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int isConnection() {
|
|
||||||
getInstance();
|
|
||||||
return api.isConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -26,12 +26,12 @@ var exec = require('cordova/exec');
|
|||||||
* @param {*} success
|
* @param {*} success
|
||||||
* @param {*} error
|
* @param {*} error
|
||||||
*/
|
*/
|
||||||
exports.print = async function (data,info) {
|
exports.print = async function (data,info,cfg) {
|
||||||
return new Promise((resolve, reject) => exec(resolve,reject, 'JcPrinter', 'print', [data,info]));
|
return new Promise((resolve, reject) => exec(resolve,reject, 'JcPrinter', 'print', [data,info,cfg||{}]));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getList = function (arg0) {
|
exports.getList = function () {
|
||||||
return new Promise((resolve, reject) => exec(resolve,reject, 'JcPrinter', 'getList', [arg0]));
|
return new Promise((resolve, reject) => exec(resolve,reject, 'JcPrinter', 'getList', []));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.connectPrinter = function (arg0) {
|
exports.connectPrinter = function (arg0) {
|
||||||
@ -39,8 +39,8 @@ exports.connectPrinter = function (arg0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.isConnection = function (arg0) {
|
exports.isConnection = function () {
|
||||||
return new Promise((resolve, reject) => exec(resolve,reject,'JcPrinter', 'isConnection', [arg0]));
|
return new Promise((resolve, reject) => exec(resolve,reject,'JcPrinter', 'isConnection', []));
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Instance = {
|
exports.Instance = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user