Working Base64 encoding.

This commit is contained in:
Braden Shepherdson 2013-01-15 11:48:09 -05:00
parent f145605c63
commit 03b974ee3f
2 changed files with 4 additions and 6 deletions

View File

@ -25,6 +25,7 @@ import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import android.util.Base64;
import android.util.Log;
public class BinaryEcho extends CordovaPlugin {
@ -43,12 +44,8 @@ public class BinaryEcho extends CordovaPlugin {
//CordovaJSONArray cdvArgs = (CordovaJSONArray) args;
//byte[] data = cdvArgs.getArrayBuffer(0);
Log.i("Braden", "BinaryEcho top");
String str = args.getString(0);
byte[] data = args.getString(0).getBytes();
byte[] data = Base64.decode(args.getString(0), Base64.DEFAULT);
Log.i("Braden", "byte[] retrieved: " + data.length);
for (int i = 0; i < 10; i++) {
Log.i("Braden", str.substring(i, i+1) + " " + data[i]);
}
// Don't return any result now, since status results will be sent when events come in from broadcast receiver
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, data);

View File

@ -21,6 +21,7 @@ package org.apache.cordova.api;
import org.json.JSONArray;
import org.json.JSONObject;
import android.util.Base64;
import android.util.Log;
public class PluginResult {
@ -73,7 +74,7 @@ public class PluginResult {
public PluginResult(Status status, byte[] data) {
this.status = status.ordinal();
this.messageType = MESSAGE_TYPE_ARRAYBUFFER;
this.encodedMessage = new String(data);
this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP);
Log.i("Braden", "Message.length() = " + this.encodedMessage.length());
}