Create file from byte array without saving to file directory

时间:2015-06-25 19:07:35

标签: java android pdf

I am working on an Android project where I have a PDF file as byte array. My goal is to render this PDF file and show to user in my application (without calling any other third-party PDF viewer). For security reasons, even temporarily, I am not allowed to create file in phone directory. Android 5.0, came with a PdfRenderer library where you pass FileDescriptor, but I can't use it. Is there any way to achieve this? EDIT: @Deprecated public static ParcelFileDescriptor fromData(byte[] data, String name) throws IOException { if (data == null) return null; MemoryFile file = new MemoryFile(name, data.length); if (data.length > 0) { file.writeBytes(data, 0, 0, data.length); } file.deactivate(); FileDescriptor fd = file.getFileDescriptor(); return fd != null ? new ParcelFileDescriptor(fd) : null; } Thanks

0 个答案:

没有答案