mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
Add a new type to the Native->JS bridge for binary strings.
It's needed since the bridge truncates strings that have null characters in them :(.
This commit is contained in:
parent
d25b73f47d
commit
7755a902dd
@ -409,6 +409,9 @@ public class NativeToJsMessageQueue {
|
|||||||
case PluginResult.MESSAGE_TYPE_STRING: // s
|
case PluginResult.MESSAGE_TYPE_STRING: // s
|
||||||
ret += 1 + pluginResult.getStrMessage().length();
|
ret += 1 + pluginResult.getStrMessage().length();
|
||||||
break;
|
break;
|
||||||
|
case PluginResult.MESSAGE_TYPE_BINARYSTRING:
|
||||||
|
ret += 1 + pluginResult.getMessage().length();
|
||||||
|
break;
|
||||||
case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
|
case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
|
||||||
ret += 1 + pluginResult.getMessage().length();
|
ret += 1 + pluginResult.getMessage().length();
|
||||||
break;
|
break;
|
||||||
@ -451,7 +454,11 @@ public class NativeToJsMessageQueue {
|
|||||||
sb.append('s');
|
sb.append('s');
|
||||||
sb.append(pluginResult.getStrMessage());
|
sb.append(pluginResult.getStrMessage());
|
||||||
break;
|
break;
|
||||||
case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
|
case PluginResult.MESSAGE_TYPE_BINARYSTRING: // S
|
||||||
|
sb.append('S');
|
||||||
|
sb.append(pluginResult.getMessage());
|
||||||
|
break;
|
||||||
|
case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: // A
|
||||||
sb.append('A');
|
sb.append('A');
|
||||||
sb.append(pluginResult.getMessage());
|
sb.append(pluginResult.getMessage());
|
||||||
break;
|
break;
|
||||||
|
@ -71,8 +71,12 @@ public class PluginResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PluginResult(Status status, byte[] data) {
|
public PluginResult(Status status, byte[] data) {
|
||||||
|
this(status, data, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PluginResult(Status status, byte[] data, boolean binaryString) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.messageType = MESSAGE_TYPE_ARRAYBUFFER;
|
this.messageType = binaryString ? MESSAGE_TYPE_BINARYSTRING : MESSAGE_TYPE_ARRAYBUFFER;
|
||||||
this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP);
|
this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +147,9 @@ public class PluginResult {
|
|||||||
public static final int MESSAGE_TYPE_BOOLEAN = 4;
|
public static final int MESSAGE_TYPE_BOOLEAN = 4;
|
||||||
public static final int MESSAGE_TYPE_NULL = 5;
|
public static final int MESSAGE_TYPE_NULL = 5;
|
||||||
public static final int MESSAGE_TYPE_ARRAYBUFFER = 6;
|
public static final int MESSAGE_TYPE_ARRAYBUFFER = 6;
|
||||||
|
// Use BINARYSTRING when your string may contain null characters.
|
||||||
|
// This is required to work around a bug in the platform :(.
|
||||||
|
public static final int MESSAGE_TYPE_BINARYSTRING = 7;
|
||||||
|
|
||||||
public static String[] StatusMessages = new String[] {
|
public static String[] StatusMessages = new String[] {
|
||||||
"No result",
|
"No result",
|
||||||
|
Loading…
Reference in New Issue
Block a user