处理打印数组参数报错的问题
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.callback.PrintCallback;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -98,23 +100,26 @@ public class JcPrinter extends CordovaPlugin {
|
||||
return true;
|
||||
case "action":
|
||||
String methodName = args.optString(0);
|
||||
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){
|
||||
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;
|
||||
}
|
||||
Log.d(TAG,"action-method:"+methodName);
|
||||
for(Method m:this.methods){
|
||||
String name = m.getName();
|
||||
if(m.getName().equals(methodName)){
|
||||
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);
|
||||
callbackContext.success();
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
@ -123,11 +128,14 @@ public class JcPrinter extends CordovaPlugin {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
case "generateLabelJson":
|
||||
callbackContext.success(new String(Util.getInstance().generateLabelJson()));
|
||||
return true;
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
callbackContext.error(e.getMessage());
|
||||
}
|
||||
return false;
|
||||
@ -310,10 +318,8 @@ public class JcPrinter extends CordovaPlugin {
|
||||
return;
|
||||
}
|
||||
List<String>pageData = new ArrayList<>();
|
||||
JSONArray array= data.optJSONArray(pageIndex);
|
||||
for(int i=0;i<array.length();i++){
|
||||
pageData.add(array.optString(i));
|
||||
}
|
||||
String dataStr= data.optString(pageIndex-1);
|
||||
pageData.add(dataStr);
|
||||
Util.getInstance().commitData(pageData,info);
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user