Following is my html content which i want to show in the webview using android sdk. It will displays only
//Please
But when I put this HTML content into the browser then it shows differently.
<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework help help with homework homework assignments elementary school high school middle school // --><font color="#60c000" size="4"><strong>Please!</strong></font>
Please suggest how to resolve this problem
I have another problem that in HTML content there is a tag
<img src="http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif" border="0" />
in this images does not shows.
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.
The loadUrl() and loadData() methods of Android WebView class are used to load and display web page.
Yes you can, you can use javascript to get webpage content. Then use the webview jsInterface to return the content to you java code.
This example works for me:
public class SimpleMusicStream extends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); WebView wv = (WebView) findViewById(R.id.WebView01); final String mimeType = "text/html"; final String encoding = "UTF-8"; String html = "<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework" + "help help with homework homework assignments elementary school high school middle school" + "// --><font color='#60c000' size='4'><strong>Please!</strong></font>" + "<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif' />"; wv.loadDataWithBaseURL("", html, mimeType, encoding, ""); } }
And don't forget to add:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
in your AndroidManifest.xml file
Either you can do it as above or put html file into the asset folder and the use it loke this to display it
view.loadUrl("file:///android_asset/FILENAME.html");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With