Skip to content

Latest commit

 

History

History
64 lines (49 loc) · 1.96 KB

README.md

File metadata and controls

64 lines (49 loc) · 1.96 KB

WebpageDownloader

release ci license

An Android and Kotlin library to download webpages for offline viewing.

It will download all assets required to render the chosen webpage and rewrite all links in the webpage to use the downloaded assets

The example app is available on Google Play

home wikipedia

To use this in your application you will need to add jitpack to the repositories section of your build.gradle file:

allprojects {
    repositories {
        //...
        maven { url 'https://jitpack.io' }
    }
}

and then add it as a dependency:

dependencies {
    implementation 'com.github.diebietse:webpage-downloader:<latest-release>'
}

You can then download a webpage (in a background thread) with something like:

val url = "https://en.wikipedia.org/wiki/Main_Page"
val downloadDir = File(application.filesDir, "downloads")
val pageId = url.hashCode().absoluteValue.toString()
try {
    WebpageDownloader().download(url, DefaultFileSaver(File(downloadDir, pageId)))
} catch (e: Exception) {
    Log.e(TAG, "Download Failed", e)
}

And render it in a WebView with:

webView.settings.javaScriptEnabled = true
webView.settings.allowFileAccess = true
webView.loadUrl("file://${downloadDir}/${pageId}/index.html")