James
James

Reputation: 14101

Load PDF from assets folder in android

I have a pdf in my assets folder. I want to load in my activity using a webview. Is it possible. or is there anyother way of doing that.

Upvotes: 1

Views: 3023

Answers (2)

Dr.J
Dr.J

Reputation: 1218

To get the asset, you will want to use the AssetManager to load the file.

The problem will be rendering the PDF file, unless your WebView is able to render the file you will end up with jumpled garbage. You can also access it from Resources, but again, WebView doesn't know how to render PDFs.

Old Mailing list about this

openRawResource(int id, TypedValue value) Open a data stream for reading a raw resource.

-- edit --

So if you just wanted the WebView to prompt the user to "download" the PDF file from the application, then you want to do something like what WebViewDemo does:

mWebView.loadUrl("file:///android_asset/demo.html");

or it might make more sense to use the setDownloadListener or going through loadDataWithBaseUrl methods

Upvotes: 0

Jazz
Jazz

Reputation:

u can do onething create a folder named "raw" in "res" then put ur file there in code write this

getResources().openRawResource(R.raw.filename)

Upvotes: 1

Related Questions