This depends on which PDF reader you are using.
Some can access items from within the assets folder, others need a
FileStream and some need the URI to the location.
For consistency, in that some documents we needed were stored in the
package and all others were from the file system, we chose to copy the PDF
to the file system and access with a URI path.
You can use an InputStream, OutputStream and a buffer.
Something like:
InputStream inputStream = context.getAssets().open( "yourpdf.pdf" );
FileOutputStream outputStream = context.openFileOutput( "yourpdf.pdf",
Context.MODE_PRIVATE | Context.MODE_WORLD_READABLE );
byte[] buffer = new byte[1024];
int bytesRead;
while( ( bytesRead = inputStream.read( buffer ) ) ! = 1 )
{
outputStream.write( buffer, 0, bytesRead );
}
inputStream.close();
outputStream.flush();
outputStream.close();
That will write the file from the package (assets folder) to the Private
folder for your application. You can then pass it's URI to other
applications with an intent and they can use it, that's what the
MODE_WORLD_READABLE does.
You can easily pull the full path of the file by using:
((File)context.getFileStreamPath( "yourpdf.pdf" )).getAbsolutePath()
Which will return a string with something like "/data/data/<your
app>/files/yourpdf.pdf
Hope that helps!
(If you want to render the PDF to the screen, that's a completely different
deal altogether and you'll need a PDF renderer to do that!)
On Thursday, 23 August 2012 15:24:11 UTC+1, Saurabh Khemka wrote:
>
> How can I access a .pdf file stored in assets folder or res/raw folder in
> my code?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en