@@ -10,12 +10,19 @@ import android.webkit.WebView
10
10
import android.webkit.WebViewClient
11
11
import kotlinx.android.synthetic.main.activity_webview.*
12
12
import android.webkit.WebSettings
13
+ import android.webkit.WebStorage
14
+ import android.webkit.WebChromeClient
15
+
16
+
13
17
14
18
15
19
16
20
class MainActivity : AppCompatActivity () {
17
21
18
22
@SuppressLint(" SetJavaScriptEnabled" )
23
+
24
+
25
+
19
26
override fun onCreate (savedInstanceState : Bundle ? ) {
20
27
super .onCreate(savedInstanceState)
21
28
@@ -24,6 +31,29 @@ class MainActivity : AppCompatActivity() {
24
31
val mWebView = findViewById<WebView >(R .id.webview)
25
32
26
33
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
27
57
webSettings.javaScriptEnabled = true
28
58
mWebView.loadUrl(getString(R .string.website_url))
29
59
mWebView.webViewClient = HelloWebViewClient ()
0 commit comments