Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display an HTML page from raw folder in res with android Webview?

I have a web page stored in my res/raw folder in android app. I want to access it and load it in the webview in my activity. Can anyone please tell me how am I supposed to do that. I have tried

webView.loadUrl(getResources().openRawResource(R.raw.myHtmlPage).toString());

but it dint work rather it gives a broken page.

kindly help me out.

regards FAS

like image 655
Fahad Avatar asked Dec 26 '10 20:12

Fahad


People also ask

How do I display HTML content in WebView?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken web view to show html content.

Is it possible to get data from HTML forms into Android while WebView?

Yes you can, you can use javascript to get webpage content. Then use the webview jsInterface to return the content to you java code.

Which method is used to load HTML content in WebView?

The loadUrl() and loadData() methods of Android WebView class are used to load and display web page.


1 Answers

Do you mean you have the raw html as a string such as "<html>...</html>"?

If so then Webview.loadData() or Webview.loadDataWithBaseUrl() should work.

like image 138
Squonk Avatar answered Oct 02 '22 12:10

Squonk