mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
Add CordovaArguments helper to decode ArrayBuffers
This commit is contained in:
parent
15a5c89e86
commit
ff1d943a69
@ -25,8 +25,6 @@ import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
public class BinaryEcho extends CordovaPlugin {
|
||||
|
||||
/**
|
||||
@ -40,9 +38,7 @@ public class BinaryEcho extends CordovaPlugin {
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
|
||||
try {
|
||||
if (action.equals("echo")) {
|
||||
//CordovaJSONArray cdvArgs = (CordovaJSONArray) args;
|
||||
//byte[] data = cdvArgs.getArrayBuffer(0);
|
||||
byte[] data = Base64.decode(args.getString(0), Base64.DEFAULT);
|
||||
byte[] data = CordovaArguments.getArrayBuffer(args, 0);
|
||||
|
||||
// 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);
|
||||
|
36
framework/src/org/apache/cordova/CordovaArguments.java
Normal file
36
framework/src/org/apache/cordova/CordovaArguments.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package org.apache.cordova;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
public class CordovaArguments {
|
||||
public static byte[] getArrayBuffer(JSONArray args, int index) throws JSONException {
|
||||
Log.i("Braden", "getting array buffer at index " + index);
|
||||
String encoded = args.getString(index);
|
||||
Log.i("Braden", encoded);
|
||||
return Base64.decode(encoded, Base64.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user