开发者

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 an开发者_如何学Goyother way of doing that.


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜