1.what
i want to return big data (big than 8k) to javascript,but cordova said parse error.
2.fixed
in java:
if (action.equals("fetch_installed_apps")) {
class MyRunnable implements Runnable{
public CallbackContext callbackContext;
public void run() {
JSONArray ary = PackageHelper.fetch_installed_apps();
JSONArray ary2;
PluginResult pluginResult;
PluginResult.Status status = PluginResult.Status.OK;
int num = 10;
try{
for(int i=0,c=(ary.length()+num-1)/num;i<c;++i){
ary2 = new JSONArray();
for(int j=i*num,c2=Math.min(j+num, ary.length());j<c2;++j){
ary2.put(ary.get(j));
}
pluginResult = new PluginResult(status, ary2);
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);
}
}catch(Exception e){
e.printStackTrace();
}
ary2 = new JSONArray();
pluginResult = new PluginResult(status, ary2);
pluginResult.setKeepCallback(false);
callbackContext.sendPluginResult(pluginResult);
}
};
MyRunnable runnable = new MyRunnable();
runnable.callbackContext = callbackContext;
cordova.getThreadPool().execute(runnable);
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);
return true;
}
in javascript:
fetch_installed_apps:function(successCallback, errorCallback) {
var data = [];
return exec(function(items){
if(items && items.length){
for(var i=0,c=items.length;i<c;++i)
data.push(items[i]);
}
else{
successCallback(data);
}
}, errorCallback, "PkrssPlugin", "fetch_installed_apps", []);
},
3. last
thanks your read!
No comments:
Post a Comment