mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
Add support for null PluginResult payloads.
https://issues.apache.org/jira/browse/CB-1744
This commit is contained in:
parent
a2f35d2bda
commit
0eee2293dc
@ -27,7 +27,7 @@ public class Echo extends CordovaPlugin {
|
||||
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
|
||||
final String result = args.getString(0);
|
||||
final String result = args.isNull(0) ? null : args.getString(0);
|
||||
if ("echo".equals(action)) {
|
||||
callbackContext.success(result);
|
||||
return true;
|
||||
|
@ -391,19 +391,15 @@ public class NativeToJsMessageQueue {
|
||||
int statusLen = String.valueOf(pluginResult.getStatus()).length();
|
||||
int ret = 2 + statusLen + 1 + jsPayloadOrCallbackId.length() + 1;
|
||||
switch (pluginResult.getMessageType()) {
|
||||
case PluginResult.MESSAGE_TYPE_BOOLEAN:
|
||||
case PluginResult.MESSAGE_TYPE_BOOLEAN: // f or t
|
||||
case PluginResult.MESSAGE_TYPE_NULL: // N
|
||||
ret += 1;
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_NUMBER: // n
|
||||
ret += 1 + pluginResult.getMessage().length();
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_STRING: // s
|
||||
if (pluginResult.getStrMessage() == null) {
|
||||
ret += 1;
|
||||
}
|
||||
else {
|
||||
ret += 1 + pluginResult.getStrMessage().length();
|
||||
}
|
||||
ret += 1 + pluginResult.getStrMessage().length();
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_JSON:
|
||||
default:
|
||||
@ -433,15 +429,16 @@ public class NativeToJsMessageQueue {
|
||||
case PluginResult.MESSAGE_TYPE_BOOLEAN:
|
||||
sb.append(pluginResult.getMessage().charAt(0)); // t or f.
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_NULL: // N
|
||||
sb.append('N');
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_NUMBER: // n
|
||||
sb.append('n')
|
||||
.append(pluginResult.getMessage());
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_STRING: // s
|
||||
sb.append('s');
|
||||
if (pluginResult.getStrMessage() != null) {
|
||||
sb.append(pluginResult.getStrMessage());
|
||||
}
|
||||
sb.append(pluginResult.getStrMessage());
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_JSON:
|
||||
default:
|
||||
|
@ -34,7 +34,7 @@ public class PluginResult {
|
||||
|
||||
public PluginResult(Status status, String message) {
|
||||
this.status = status.ordinal();
|
||||
this.messageType = MESSAGE_TYPE_STRING;
|
||||
this.messageType = message == null ? MESSAGE_TYPE_NULL : MESSAGE_TYPE_STRING;
|
||||
this.strMessage = message;
|
||||
}
|
||||
|
||||
@ -133,6 +133,7 @@ public class PluginResult {
|
||||
public static final int MESSAGE_TYPE_JSON = 2;
|
||||
public static final int MESSAGE_TYPE_NUMBER = 3;
|
||||
public static final int MESSAGE_TYPE_BOOLEAN = 4;
|
||||
public static final int MESSAGE_TYPE_NULL = 5;
|
||||
|
||||
public static String[] StatusMessages = new String[] {
|
||||
"No result",
|
||||
|
Loading…
Reference in New Issue
Block a user