What does file:///android_asset/www/index.html mean?

后端 未结 6 852
情书的邮戳
情书的邮戳 2020-12-05 00:35

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

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 01:16

    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.

提交回复
热议问题