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