I want to know what does file:///
mean while loading a html file from the assets folder in android
Is it an absolute path name which points to the root directory?
I saw this in the tutorial for phonegap by the way.
This question is related to
android
It took me more than 4 hours to fix this problem. I followed the guide from http://docs.phonegap.com/en/2.1.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android
I'm using Android Studio (Eclipse with ADT could not work properly because of the build problem).
Solution that worked for me:
I put the /assets/www/index.html under app/src/main/assets directory. (take care AndroidStudio has different perspectives like Project or Android)
use super.loadUrl("file:///android_asset/www/index.html"); instead of super.loadUrl("file:///android_assets/www/index.html"); (no s)
The URI "file:///android_asset/"
points to YourProject/app/src/main/assets/
.
Note: android_asset/
uses the singular (asset) and src/main/assets
uses the plural (assets).
Suppose you have a file YourProject/app/src/main/assets/web_thing.html
that you would like to display in a WebView. You can refer to it like this:
WebView webViewer = (WebView) findViewById(R.id.webViewer);
webView.loadUrl("file:///android_asset/web_thing.html");
The snippet above could be located in your Activity class, possibly in the onCreate
method.
Here is a guide to the overall directory structure of an android project, that helped me figure out this answer.
If someone uses AndroidStudio make sure that the assets folder is placed in
app/src/main/assets
directory.
it's file:///android_asset/... not file:///android_assets/... notice the plural of assets is wrong even if your file name is assets
It is actually called file:///android_asset/index.html
file:///android_assets/index.html
will give you a build error.
Source: Stackoverflow.com