Open chatbaz opened 10 years ago
PDF cannot be loaded from Assets folder. You should copy it on sdcard before opening it. http://stackoverflow.com/questions/4447477/android-how-to-copy-files-in-assets-to-sdcard
I have uploaded code which is tested on device and emulator also.
you may see following link:
I have downloaded pdf file saved on external storage, its still showing loading indicator and not showing pdf
The files in the assets directory doesent get unpacked. Instead they are read directly from the .apk file. Instead you'll have to extract the asset and write it to a seperate file and then get it's path and add it as extra in the intent.
Something like this:
public String getAssetsPdfPath(Context context) { String filePath = context.getFilesDir() + File.separator + "myFile.pdf"; File destinationFile = new File(filePath);
try { FileOutputStream outputStream = new FileOutputStream(destinationFile); InputStream inputStream = context.getAssets().open("myFile.pdf"); byte[] buffer = new byte[1024]; int length = 0; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } outputStream.close(); inputStream.close(); } catch (IOException e) { Log.e(context.getClass().getSimpleName(), "Error."); }
return destinationFile.getPath(); }
And that's it. Hope this helps anyone. Cheers.
It doesn't open files from Assets. When the PDF activity open it shows a Loading dialog and do nothing!