我正在使用delphi xe6来创建Android应用程序。 Android应用程序正在从Webservice服务器下载pdf文件作为字节数组。通过使用TFileStream,创建了pdf文件并编写了缓冲区(字节数组)。
但是,问题是pdf文件没有创建。并且当尝试打开文件时收到错误,就像没有文件一样。
如果我开发与桌面应用程序相同的pdf文件正在正确创建。
以下是代码段。
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;
答案 0 :(得分:1)
感谢您的回答。我找到了解决方案。这里是更改的代码段
FileStream := FileStream.Create(TPath.Combine(TPath.GetSharedDocumentsPath, 'sample.pdf'), fmCreate or fmOpenWrite); try FileResponse := GetIFileTransfer.GetFile; FileStream.WriteBuffer(FileResponse.Bytes[0], Length(FileResponse.Bytes)); finally FileStream.Free; end; Intent := TJIntent.Create; Intent.setAction(TJIntent.JavaClass.ACTION_VIEW); Intent.setDataAndType(StrToJURI('file://' + TPath.Combine(TPath.GetSharedDocumentsPath, 'Sample.pdf')), StringToJString('application/pdf')); SharedActivity.startActivity(Intent);