How to convert TJavaArray to TBytes with Delphi

uses
  Androidapi.JNIBridge,
  Androidapi.JNI.JavaTypes;

Solution #1
function ConvertJBytes2TBytes(data: TJavaArray; len: Integer): TBytes;
begin
  SetLength(result, len);
  if len > 0 then
    Move(data.Data^, result[0], len);
end;

Solution #2
function ConvertJBytes2TBytes(data: TJavaArray): TBytes;
begin
  SetLength(result, data.Length);
  if data.Length > 0 then
    Move(data.Data^, result[0], data.Length);
end;

Comments