James Parsons
James Parsons

Reputation: 6057

Where should I store local files for a WebView

Lets say I want to store a JavaScript file in my app for an Android WebView to use. Where should I put this file? My first though would be somewhere in the assets folder, but I am not too sure.

Upvotes: 1

Views: 551

Answers (1)

ʍѳђઽ૯ท
ʍѳђઽ૯ท

Reputation: 16976

Check the following link and explanations:

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.

There is also a raw folder you can even use that, but:

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.

For completing the answer, you can easily use file:///android_asset/

Have a look at this question: Android WebView Javascript from assets

Upvotes: 1

Related Questions