Blog purpose for android basic example for android app developer. any query please my contact

Friday 27 September 2024

what is Assets Folder in Android Studio

 what is Assets Folder in Android Studio


It can be noticed that unlike Eclipse ADT (App Development Tools), Android Studio doesn’t contain an Assets folder in which we usually use to keep the web files like HTML. 



In Android one can store the raw asset file like JSON, Text, mp3, HTML, pdf, etc in two possible locations:


assets

res/raw folder


1. Flexible File Name: (assets is better)


assets: The developer can name the file name in any way, like having capital letters (fileName) or having space (file name).

res/raw: In this case, the name of the file is restricted. File-based resource names must contain only lowercase a-z, 0-9, or underscore.

2. Store in subdirectory: (possible in assets)


assets: If the developer wants to categories the files into subfolders, then he/she can do it in assets like below.


res/raw: In this case, files can only be in the root folder.


3. Compile-time checking: (possible in res/raw)


assets: Here, the way to read it into InputStream is given below. If the filename doesn’t exist, then we need to catch it.


assets.open(“filename”)




4. List filenames at runtime: (possible in assets)


assets: If the developer wants to list all the files in the assets folder, he/she has used the list() function and provide the folder name or ” “ on the root folder as given below.



5. Filename accessible from XML: (possible in res/raw) 


assets: No simple way the developer can arrange an XML file (e.g. AndroidManifest.xml) to point to the file in the assets folder.

res/raw: In any XML files like in Java, the developer can access the file in res/raw using @raw/filename easily.


No comments:

Post a Comment