Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Work with ByteArray on an AIR Native Extension
* Project: ANE-Google-Analytics
* Author: Alessandro Bianco
* Website:
* Twitter: @alebianco
* Created: 23/12/12 10.42
* Copyright © 2013 Alessandro Bianco
import android.util.Log;
import com.adobe.fre.FREByteArray;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
import java.nio.ByteBuffer;
public class SendBytes implements FREFunction {
public FREObject call(FREContext context, FREObject[] args) {
try {
FREByteArray ba = (FREByteArray) args[0];
ByteBuffer bb = ba.getBytes();
byte[] bytes = new byte[(int) ba.getLength()];
String str = new String(bytes);
Log.d("ANE", "My ByteArray is long " + bytes.length + " bytes and contains '" + str + "'");
} catch (Exception e) {
Log.e("ANE", "An error occurred while reading the ByteArray", e);
FREByteArray result = null;
try {
result = FREByteArray.newByteArray();
FREObject content = FREObject.newObject("hello to you!");
FREObject[] params = new FREObject[] {content};
result.callMethod("writeUTFBytes", params);
} catch (Exception e) {
Log.e("ANE", "An error occurred while writing the ByteArray", e);
return result;
// After initializing the extension ...
var ba:ByteArray = new ByteArray()
ba.writeUTFBytes("hello world");
var reply:ByteArray ="sendBytes", ba) as ByteArray;

This comment has been minimized.

Copy link

Oldes commented Sep 23, 2016

Thank you! It is exactly what I was searching for and could not found anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.