Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed a piece of HTML code or Javascript script inside webview in android

I got a small piece of Javascript and HTML code of a table containing statistics that I want to embed into a WebView in my android app. How do i go about doing that. Can someone suggest me with an example and sample code. Please help

like image 403
Jeris Avatar asked Dec 26 '22 23:12

Jeris


1 Answers

  WebView webView;

String htmlPre = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"></head><body style='margin:0; pading:0; background-color: black;'>";  
    String htmlCode = 
            " <embed style='width:100%; height:100%' src='http://www.platipus.nl/flvplayer/download/1.0/FLVPlayer.swf?fullscreen=true&video=http://www.platipus.nl/flvplayer/download/pl-600.flv&autoplay=true' " +
            "  autoplay='true' " +
            "  quality='high' bgcolor='#000000' " +
            "  name='VideoPlayer' align='middle'" + // width='640' height='480' 
            "  allowScriptAccess='*' allowFullScreen='true'" +
            "  type='application/x-shockwave-flash' " +
            "  pluginspage='http://www.macromedia.com/go/getflashplayer' />" +
            "";
    String htmlPost = "</body></html>";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main); 

    webView = (WebView)findViewById(R.id.webview);

webView.loadDataWithBaseURL("null", htmlPre+htmlCode+htmlPost, "text/html", "UTF-8", null); 

}

above example use the html code in webView.

like image 67
Amit kumar Avatar answered Dec 29 '22 15:12

Amit kumar