android - 我应该在哪里存储 WebView 的本地文件

标签 android android-webview

假设我想在我的应用程序中存储一个 JavaScript 文件以供 Android WebView 使用。我应该把这个文件放在哪里?我的第一个虽然会在 assets 文件夹中的某个地方,但我不太确定。

最佳答案

检查以下链接和解释:

http://www.41post.com/3985/programming/android-loading-files-from-the-assets-and-raw-folders

The Assets folder is an 'appendix' directory. The R class does not generate IDs for the files placed there, so its less compatible with some Android classes and methods. Also, it’s much slower to access a file inside it, since you will need to get a handle to it based on a String. There is also a 1MB size limit for files placed inside the Assets folder, however some operations are more easily done by placing files in this folder, like copying a database file to the system’s memory. There’s no (easy) way to create an Android XML reference to files inside the Assets folder.

还有一个 raw 文件夹,您甚至可以使用它,但是:

it’s important to highlight the main differences between the raw folder and the Assets folder. Since raw is a subfolder of Resources (res), Android will automatically generate an ID for any file located inside it. This ID is then stored an the R class that will act as a reference to a file, meaning it can be easily accessed from other Android classes and methods and even in Android XML files.

Using the automatically generated ID is the fastest way to have access to a file in Android.

要完成答案,您可以轻松使用 file:///android_asset/

看看这个问题: Android WebView Javascript from assets

关于android - 我应该在哪里存储 WebView 的本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34858924/

相关文章:

android - 在更新到目标 sdk 29 之前,Javascript 无法在 Android WebView 上运行

android - 使用 Retrofit 发送带有参数的 Post 请求

android - 面临 GCM 问题 - 设备未收到消息

Android:获取应用程序的描述

java - WebView 第二次显示黑屏?

javascript - 在混合 android 应用程序中导航时在 chrome 设备中看到多个分离的 webview 实例

Android - 仅使用其名称的一部分检查文件是否存在

android - 如何在安装android应用程序时创建sqlite数据库?

加载 Flash 网站时,Android Webview 滚动行为异常

android - 使用 android WebView 加载现有的 .html 文件