I'm going to show a pdf in my application, and the pdf has to be bundled with the application.
What is a good way to do this?
I have read that it might be possible to do this by adding the pdf file to a res/raw folder and read it from there, but i get project errors when i put the pdf file there.
So i tried to put the pdf file in the asset folder of the project, and it gave no errors.
This is how i've tried to show the pdf:
File pdfFile = new File("res/raw/file.pdf");
Uri path = Uri.fromFile(pdfFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
You would be able to show it from
assets/ if your application actually implemented a PDF reader. Since you want it to be displayed in a separate application (such as Adobe Reader), I suggest doing the following:
Intentjust like you are doing now, except use
getAbsolutePath()on the newly created file for the intent's data.
Be aware that a user might not have a PDF reading application. In this case, it is useful to catch the
ActivityNotFoundException and show an appropriate message.