Skip to content Skip to sidebar Skip to footer

Android Webview Download And View Pdf, Xls Or Doc Files

I'm making an android app that uses a webview to navigate through a specific website. The thing is that I want users to be able to view pdf, .xls or .doc documents that are in the

Solution 1:

You'll have to download the files first, so Android can find an appropriate application to open them with, since Uri.parse(url) will give you a website address, which is normally assigned to the browser (and will therefore open in it).

To download the files, you can use the DownloadManager-service or write your own code to do so. Once you have the file in a temporary location, you can open it by using your above method.

If you want to delete the file after the user viewed it, one idea would be to do it in your activities onResume()-method, which will be called when the user navigates back from viewing the file (using the back-button).

Although, I would rather put the files in the internal cache and wipe it every now and then. Android will do a little house-keeping itself, too:

When the device is low on internal storage space, Android may delete these cache files to recover space. However, you should not rely on the system to clean up these files for you. You should always maintain the cache files yourself and stay within a reasonable limit of space consumed, such as 1MB. When the user uninstalls your application, these files are removed.

Post a Comment for "Android Webview Download And View Pdf, Xls Or Doc Files"