Skip to content

Commit 90c0d69

Browse files
committed
Build with Offline Data supported
1 parent 183a930 commit 90c0d69

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package="tk.merith.devdocs">
55

66
<uses-permission android:name="android.permission.INTERNET" />
7-
7+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
8+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
9+
810
<uses-feature
911
android:name="android.hardware.touchscreen"
1012
android:required="true" />

app/src/main/java/tk/merith/devdocs/MainActivity.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ import android.webkit.WebView
1010
import android.webkit.WebViewClient
1111
import kotlinx.android.synthetic.main.activity_webview.*
1212
import android.webkit.WebSettings
13+
import android.webkit.WebStorage
14+
import android.webkit.WebChromeClient
15+
16+
1317

1418

1519

1620
class MainActivity : AppCompatActivity() {
1721

1822
@SuppressLint("SetJavaScriptEnabled")
23+
24+
25+
1926
override fun onCreate(savedInstanceState: Bundle?) {
2027
super.onCreate(savedInstanceState)
2128

@@ -24,6 +31,29 @@ class MainActivity : AppCompatActivity() {
2431
val mWebView = findViewById<WebView>(R.id.webview)
2532

2633
val webSettings = mWebView.settings
34+
//begin custom crap
35+
36+
mWebView.setWebChromeClient(object : WebChromeClient() {
37+
override fun onReachedMaxAppCacheSize(spaceNeeded: Long, totalUsedQuota: Long,
38+
quotaUpdater: WebStorage.QuotaUpdater) {
39+
quotaUpdater.updateQuota(spaceNeeded * 2)
40+
}
41+
})
42+
43+
mWebView.getSettings().setDomStorageEnabled(true)
44+
45+
// Set cache size to 8 mb by default. should be more than enough
46+
mWebView.getSettings().setAppCacheMaxSize(1024 * 1024 * 512)
47+
48+
// This next one is crazy. It's the DEFAULT location for your app's cache
49+
// But it didn't work for me without this line.
50+
// UPDATE: no hardcoded path. Thanks to Kevin Hawkins
51+
val appCachePath = applicationContext.cacheDir.absolutePath
52+
mWebView.getSettings().setAppCachePath(appCachePath)
53+
mWebView.getSettings().setAllowFileAccess(true)
54+
mWebView.getSettings().setAppCacheEnabled(true)
55+
56+
//end custom crap
2757
webSettings.javaScriptEnabled = true
2858
mWebView.loadUrl(getString(R.string.website_url))
2959
mWebView.webViewClient = HelloWebViewClient()

0 commit comments

Comments
 (0)