forked from github/cordova-android
Working Base64 encoding.
This commit is contained in:
parent
f145605c63
commit
03b974ee3f
@ -25,6 +25,7 @@ import org.apache.cordova.api.PluginResult;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class BinaryEcho extends CordovaPlugin {
|
public class BinaryEcho extends CordovaPlugin {
|
||||||
@ -43,12 +44,8 @@ public class BinaryEcho extends CordovaPlugin {
|
|||||||
//CordovaJSONArray cdvArgs = (CordovaJSONArray) args;
|
//CordovaJSONArray cdvArgs = (CordovaJSONArray) args;
|
||||||
//byte[] data = cdvArgs.getArrayBuffer(0);
|
//byte[] data = cdvArgs.getArrayBuffer(0);
|
||||||
Log.i("Braden", "BinaryEcho top");
|
Log.i("Braden", "BinaryEcho top");
|
||||||
String str = args.getString(0);
|
byte[] data = Base64.decode(args.getString(0), Base64.DEFAULT);
|
||||||
byte[] data = args.getString(0).getBytes();
|
|
||||||
Log.i("Braden", "byte[] retrieved: " + data.length);
|
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
|
// 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);
|
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, data);
|
||||||
|
@ -21,6 +21,7 @@ package org.apache.cordova.api;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class PluginResult {
|
public class PluginResult {
|
||||||
@ -73,7 +74,7 @@ public class PluginResult {
|
|||||||
public PluginResult(Status status, byte[] data) {
|
public PluginResult(Status status, byte[] data) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.messageType = MESSAGE_TYPE_ARRAYBUFFER;
|
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());
|
Log.i("Braden", "Message.length() = " + this.encodedMessage.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user