Question

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.

Was it helpful?

Solution

  1. Use web.loadDataWithBaseURL instead of web.loadData (And don't forget to escape strings where it's needed)
  2. You need to add internet permission to download images and view them in your manifest file.

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

OTHER TIPS

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");

for image display you can do it like

 String str= " img src=\"http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif\" alt=\"this is img\"ALIGN=\"right\"/>";
    wv.loadData(str, "text/html", "utf-8");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top