Cannot open pdf file created by Android app

  

I am using delphi xe6 for creating the Android app.
Android app is downloading the pdf file from Webservice server as array of bytes. By using TFileStream, created the pdf file and writing the buffer(array of bytes).

But, the problem is pdf file is not creating. And when try to open the file getting error like there is no file.

The pdf file is creating properly if I develop same as desktop application.

Here is the code snippet.

FileStream := TFileStream.Create(TPath.GetDocumentsPath + PathDelim + ‘Sample.pdf’, fmCreate or fmOpenWrite);
try
FileResponse := GetIFileTransfer.GetFile; //GetIFileTransfer is Webservice object
FileStream.WriteBuffer(FileResponse.Bytes[0], Length(FileResponse.Bytes));
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setDataAndType(StrToJURI(TPath.GetDocumentsPath + PathDelim + ‘Sample.pdf’),
StringToJString(‘application/pdf’));
SharedActivity.startActivity(Intent);
finally
FileStream.Free;
end;

Comments are closed.