处理打印数组参数报错的问题
This commit is contained in:
parent
e7ce7bca2d
commit
5b60471f5b
@ -28,9 +28,11 @@ import androidx.core.app.ActivityCompat;
|
|||||||
import com.gengcon.www.jcprintersdk.bean.ImageDataInfo;
|
import com.gengcon.www.jcprintersdk.bean.ImageDataInfo;
|
||||||
import com.gengcon.www.jcprintersdk.callback.PrintCallback;
|
import com.gengcon.www.jcprintersdk.callback.PrintCallback;
|
||||||
|
|
||||||
|
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;
|
||||||
@ -98,23 +100,26 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
return true;
|
return true;
|
||||||
case "action":
|
case "action":
|
||||||
String methodName = args.optString(0);
|
String methodName = args.optString(0);
|
||||||
JSONArray methodJsonArgs = args.getJSONArray(1);
|
Log.d(TAG,"action-method:"+methodName);
|
||||||
Object[] methodArgs = new Object[methodJsonArgs.length()];
|
|
||||||
for(int i=0;i<methodJsonArgs.length();i++){
|
|
||||||
Object obj = methodJsonArgs.opt(i);
|
|
||||||
if(obj instanceof JSONArray){
|
|
||||||
Object[] array = new Object[((JSONArray) obj).length()];
|
|
||||||
for(int j=0;j<((JSONArray) obj).length();j++){
|
|
||||||
array[i] = ((JSONArray) obj).opt(j);
|
|
||||||
}
|
|
||||||
obj = array;
|
|
||||||
}
|
|
||||||
methodArgs[i] = obj;
|
|
||||||
}
|
|
||||||
for(Method m:this.methods){
|
for(Method m:this.methods){
|
||||||
String name = m.getName();
|
String name = m.getName();
|
||||||
if(m.getName().equals(methodName)){
|
if(m.getName().equals(methodName)){
|
||||||
try {
|
try {
|
||||||
|
JSONArray methodJsonArgs = args.getJSONArray(1);
|
||||||
|
Object[] methodArgs = new Object[methodJsonArgs.length()];
|
||||||
|
for(int i=0;i<methodJsonArgs.length();i++){
|
||||||
|
Object obj = methodJsonArgs.opt(i);
|
||||||
|
if(obj instanceof JSONArray){
|
||||||
|
Class a = m.getParameterTypes()[i].getComponentType();
|
||||||
|
Object array = Array.newInstance(a,((JSONArray) obj).length());
|
||||||
|
for(int j=0;j<((JSONArray) obj).length();j++){
|
||||||
|
Array.set(array,j,((JSONArray) obj).opt(j));
|
||||||
|
}
|
||||||
|
methodArgs[i] = array;
|
||||||
|
}else{
|
||||||
|
methodArgs[i] = obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
m.invoke(Util.getInstance(),methodArgs);
|
m.invoke(Util.getInstance(),methodArgs);
|
||||||
callbackContext.success();
|
callbackContext.success();
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
@ -123,11 +128,14 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case "generateLabelJson":
|
case "generateLabelJson":
|
||||||
callbackContext.success(new String(Util.getInstance().generateLabelJson()));
|
callbackContext.success(new String(Util.getInstance().generateLabelJson()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
callbackContext.error(e.getMessage());
|
callbackContext.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -310,10 +318,8 @@ public class JcPrinter extends CordovaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String>pageData = new ArrayList<>();
|
List<String>pageData = new ArrayList<>();
|
||||||
JSONArray array= data.optJSONArray(pageIndex);
|
String dataStr= data.optString(pageIndex-1);
|
||||||
for(int i=0;i<array.length();i++){
|
pageData.add(dataStr);
|
||||||
pageData.add(array.optString(i));
|
|
||||||
}
|
|
||||||
Util.getInstance().commitData(pageData,info);
|
Util.getInstance().commitData(pageData,info);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user