gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:38:13 24 4
gpt4 key购买 nike

假设我想在我的应用程序中存储一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com