Search code examples
androidarraysdebuggingandroid-ndklogcat

android c code array debug using logcat


On my native code I want to debug the byte[] array passed for android app. I want to store the byte array into a file or display it in the logcat. I could covert each char to string and print it into the logcat in my c code. Is their a better way to debug the array in the c code?


Solution

  • You can use a WritableByteChannel to dump the byte[] buffer into a file.

    FileOutputStream output = new FileOutputStream(new File("/sdcard/"+filename+".yuv"));
    WritableByteChannel channel = Channels.newChannel(output);
    ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
    channel.write(byteBuffer);
    channel.close();
    output.close();