Home > Blockchain >  Where and how to put HTML files in Android app resource files?
Where and how to put HTML files in Android app resource files?

Time:12-16

I am creating a simple Android Bible app. Bible text is structured in the bible folder as:

.
├── bible
│   ├── book_one
│   │   ├── chapter_one.html
│   │   ├── chapter_two.html
│   │   └── [...]
│   ├── book_two
│   │   ├── chapter_one.html
│   │   ├── chapter_two.html
│   │   └── [...]
│   ├── [...]
| [...]
[...]

My question are:

  • where is the appropriate place to put the bible folder in Android app project and,
  • how do I import it with the Android Studio (version Artic Fox) and,
  • how do I load those files to use it within my code?

P.S. I'm new in the Android app dev world.

CodePudding user response:

In order to put HTML files in your existing android studio project please follow steps below:

1: To add a local HTML file into your Android project there must be an asset folder in it. To create an asset folder in Android studio open your project in Android mode first as shown in the below image.

Step 1

2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder.

Step 2

3: Android Studio will open a dialog box. Keep all the settings default. Under the target source set, option main should be selected. and click on the finish button.

Step 3

4: The asset folder has been created as shown in the below image. Go to assets > right-click > New > File and a dialog box will pop up.

Step 4

5: Provide a name to your file as shown below. For example demo.html

Step 5

6: Or you can simply paste your html files into assets folder created in step 4.

7: You are done with it! Happy Coding

8: This way you can use your files from Assets folder:

webView.loadUrl("file:///android_asset/filename.html");

CodePudding user response:

It is very easy to implement. You have to just follow two simple steps as follows:

Step 1: Create an HTML page anywhere on your PC and then copy the required HTML files.

Step 2: Paste it inside the assets folder by right-clicking on the assets folder as shown in the below image.

Please check this image

  • Related