fix: 改回loadUrl(file://frame.html) - loadDataWithBaseURL导致乱码
- 框架APK始用loadUrl,避免MIME/编码问题 - 缓存HTML仍用loadDataWithBaseURL - 恢复<!DOCTYPE html>
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -13,15 +13,21 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
val cacheFile = File(filesDir, "gca_hot.html")
|
||||||
val wv = WebView(this).apply {
|
val wv = WebView(this).apply {
|
||||||
settings.javaScriptEnabled = true
|
settings.javaScriptEnabled = true
|
||||||
settings.domStorageEnabled = true
|
settings.domStorageEnabled = true
|
||||||
settings.allowFileAccess = true
|
settings.allowFileAccess = true
|
||||||
addJavascriptInterface(Bridge(this@MainActivity), "Android")
|
addJavascriptInterface(Bridge(this@MainActivity), "Android")
|
||||||
|
|
||||||
val html = assets.open("frame.html").bufferedReader().readText()
|
if (cacheFile.exists()) {
|
||||||
loadDataWithBaseURL("about:blank", html, "text/html", "UTF-8", null)
|
val html = cacheFile.readText()
|
||||||
Log.i(TAG, "Loaded frame.html (${html.length}B)")
|
loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null)
|
||||||
|
Log.i(TAG, "Loaded cached HTML (${cacheFile.length()}B)")
|
||||||
|
} else {
|
||||||
|
loadUrl("file:///android_asset/frame.html")
|
||||||
|
Log.i(TAG, "Loaded frame.html")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setContentView(wv)
|
setContentView(wv)
|
||||||
}
|
}
|
||||||
@@ -35,9 +41,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@android.webkit.JavascriptInterface
|
@android.webkit.JavascriptInterface
|
||||||
fun clearCache() {
|
fun clearCache() { File(ctx.filesDir, "gca_hot.html").delete() }
|
||||||
File(ctx.filesDir, "gca_hot.html").delete()
|
|
||||||
}
|
|
||||||
|
|
||||||
@android.webkit.JavascriptInterface
|
@android.webkit.JavascriptInterface
|
||||||
fun sha256(input: String): String {
|
fun sha256(input: String): String {
|
||||||
|
|||||||
BIN
screen-now.png
Normal file
BIN
screen-now.png
Normal file
Binary file not shown.
Reference in New Issue
Block a user