How does Android load PDF files locally

Most apps open PDF files by invoking the tool that can open PDF files in the mobile phone through intent to view PDF files. If the demand is, after users download PDF files in the app, they open them locally without using third-party tools.

How can such requirements be realized? I checked some information on the Internet and found a good open source PDF library.

It is also very simple to use. First, add the reference of pdfview

compile 'com.github.barteksc:android-pdf-viewer:2.4.0'

Reference pdfview in layout

The next step is to download the PDF file. In order to save user resources, check whether the PDF file is available locally before each download. If not, download it again.

Here I write a dialog box under loading, which is used during opening and downloading

If there is a PDF file locally, start loading the PDF file, refushui();

Pdfview loads PDF files in two forms: one is to read from the file, and the other is to read from the assets directory

There is no PDF file locally, which needs to be obtained from the server,

Downloadpdf. Getinstance(). Downloadpdf (showpdactivity. This, / / download path);

You can see that when the PDF asking price is downloaded successfully, the handler. Sendemptymessage (2);, When the case is 2, a message is sent again by calling the ddhandle passed from the page of the tool class,

The calling interface will call refushui () again after receiving the message; Use this method to open a PDF file.

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>