I tried many times and try to use HTML tag <object>, but app just crash and disappear.
Each time when I use normal html tag such as <html>, <body>, <h1>, <div>, <td>, <tr> etc. Those can be shown directly without any error.
This time I try to embed an <object> tag to webview and it always crash!
Does anyone who know how to do this directly inside code? OR, webview just cannot do this?
here is my code.
String html =
"<html>" +
"<body><h1>This is a test !!</h1>" +
"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='200' height='200'></object>" +
"<param name='quality' value='high'>" +
"<param name='allownetworking' value='internal'>" +
"<param name='allowScriptAccess' value='never'>" +
"<param name='movie' value='http://video.yutube.com/flv2.swf?i=20100129LqvamMPB&d=360.25&movie_stop=off&no_progressive=1&otag=1&sj=5&rel=1'>" +
"<param name='allowFullScreen' value='true'>" +
"<embed src='http://video.yutube.com/flv2.swf?i=20100129LqvamMPB&d=360.25&movie_stop=off&no_progressive=1&otag=1&sj=5&rel=1' width='200' height='200' quality='high' allownetworking='internal' allowscriptaccess='never' allowfullscreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed>" +
"</object>" +
"</body></html>";
mWebView.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
You have one <object> tag and two </object> tags. The first </object> has got to go.
The embed tag is for browsers that don't recognize the object tag. Those browsers will see the embed tag and will try to use it. Browsers that support the object tag will use the object and ignore the embed, as long as the embed is within the object. If the embed is outside the object, object aware browsers may load both the object and embed tags.
WebView can definitely handle the html tag. I don't think you should use loadDataWithBaseURL though, try this instead:
mWebView.loadData(html, "text/html", "UTF-8");
I'm not too sure your <object> will work though...
Here's a better way to play a YouTube video if that's all you need:
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v=<video-id>")));
Put your video id in place of the <video-id>
Related
I'm tring to load this url in a WebView :
https://crocodoc.com/view/PFk2xRsJYPjfDhhm-2nfzi1CnZtUvvXqpy7Uh7uCcFGTfiFDbVpzbgJ2kSUyGGRkf1M_eq_COHKAf14Okz0ShL0WzoNiprqf2UWXUSP7hJ0CHiCGaP4Vs7CHKJAW2A
I tried the basic way :
wv.loadUrl("..");
within an Iframe :
String str2 = "<body style=\"margin:0px;padding:0px;overflow:hidden\">\n" +
"<iframe src=\""+"https://crocodoc.com/view/"+sessionId+"\" frameborder=\"0\" style=\"overflow:hidden;height:100%;width:100%\" height=\"100%\" width=\"100%\"></iframe>\n" +
"</body>";
wv.loadData(str2, "text/html","utf-8");
With a classic client, a chrome chient, enabling more of less every WebView Setting that I could think of. But I loose the controls, I just see an horribele zommed view of the document, I can't zoom etc...
I only left :
wv.getSettings().setJavaScriptEnabled(true);
In my phone browsers It displays as I want it to.
So my question is : why ? how should I do to make it look the same way than in firefox or chrome.
Thanks
I have pictures/movies in my webview, and i have a problem with the resize.
I have a CSS for my webview in which i set
img{width:100%;}
But how to set the just height ? Because currently I have picture which take the half of the screen.
My other problem is i have
in my content, how can I delete it ?
To modify the styling of the HTML you could load a custom css like this:
final String customCssLink = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">";
webView.loadDataWithBaseURL("file:///android_asset/", customCssLink + html, "text/html", "UTF-8", null);
And you can remove all of the from the HTML like this:
String.replace(" ", "");
But with both those things you have to be very careful. Modifying HTML is just like HTML parsing a big source of bugs and rather error prone. If at all possible I would advice against doing stuff like this, but if you have no other choice try to at least be as careful as possible.
WebView web_view = (WebView) findViewById(R.id.webView1);
web_view.getSettings().setJavaScriptEnabled(true);
web_view.getSettings().setPluginsEnabled(true);
web_view.getSettings().setAllowFileAccess(true);
String data;
data = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ "<html>"
+ "<head>"
+ "<title>My First chart using FusionCharts XT</title>"
+ "<script type=\"text/javascript\" src=\"FusionCharts.js\">"
+ "</script>"
+ "</head>"
+ "<body>"
+ "<div id=\"chartContainer\">FusionCharts XT will load here!</div>"
+ "<script type=\"text/javascript\">"
+ "FusionCharts.setCurrentRenderer(\"javascript\");"
+ "var myChart = new FusionCharts(\"FusionCharts/Line.swf\", \"myChartId\", \"400\", \"300\", \"0\", \"1\" );"
+ "var dataString =\"<chart> <set label='0.00' value='0'/><set label='5.00' value='2' /><set label='7.00' value='3' /><set label='9.00' value='4' /><set label='12.00' value='2' /></chart>\"; "
+ "myChart.setXMLData(dataString);"
+ "myChart.render(\"chartContainer\");" + "</script>"
+ "</body>" + "</html>";
Log.i("info", "Html " + data);
web_view.loadData(data, "text/html; charset=UTF-8",null);
In my project i am using fusion charts. I am making a html string data and load it in WebView as in above code sample. When i run this html file in browser it runs and make me Fusion charts, But when i am doing this with for android Web view it is not loading in my Web View.
I have already Enable javascript.
I paste javascript file in to assets folder.
First of all, the browser you mentioned is a browser on your device or is it a browser in a computer?
Now, if it worked in the android browser (or a browser in your device), then the problem is because the javascript files are on your assets folder. When you indicate a resource through relative path (the way you are using), the webview searchs it relative to the same folder as your html file is. Since you are using a String as your "html file", I would recommend using the loadDataWithBaseURL(). I made an usage example below using the assets folder as the base URL, try it.
web_view.loadDataWithBaseURL("file:///android_asset/", data, "text/html", "UTF-8",null);
public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl)
Added in API level 1
Loads the given data into this WebView, using baseUrl as the base URL for the content. The base URL is used both to resolve relative URLs and when applying JavaScript's same origin policy. The historyUrl is used for the history entry.
Note that content specified in this way can access local device files (via 'file' scheme URLs) only if baseUrl specifies a scheme other than 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
If the base URL uses the data scheme, this method is equivalent to calling loadData() and the historyUrl is ignored.
Parameters
baseUrl the URL to use as the page's base URL. If null defaults to 'about:blank'.
data a String of data in the given encoding
mimeType the MIMEType of the data, e.g. 'text/html'. If null, defaults to 'text/html'.
encoding the encoding of the data
historyUrl the URL to use as the history entry. If null defaults to 'about:blank'.
You can try passing the assets folder as the baseUrl, so my guess would be that your code would be like this
Hope this helps!
I have an Android Webview where I load HTML into using loadDataWithBaseURL, some of my images are displayed a "?" as if the image is missing. I had trouble fixing that so I'm now attempting to remove images altogether. I tried to use:
webview.loadUrl("javascript:(function() { " + "document.getElementsByTagName('img')[0].style.display = 'none'; " + "})()");
But it didn't work, I'm struggling to think of another solution. The HTML code producing the images is formatted like so:
<img name="StartDate" src="images/calendar.gif" onclick="displayDatePicker('StartDate',false,'dmy','-')" alt="Press for a date picker" />
Any help would be greatly appreciated.
Try using:
webView.getSettings().setLoadsImagesAutomatically(false);
I have a problem with an URL that starts with https. It's showing a blank white screen whereas links, starting with http, loads successfully in Android webview.
With logs I'm sure that data is coming from HTTPS also but is not displaying in the view. Please help me. Some sample code or link will be most appreciated.
HI,
I read your question, I don't know what is your exact issue if you have data then you can use these line of code to display it in webview
encoding contains html tags like <p> aadfasdf asdf ds </p>
public static final String HTML_FORMAT =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">" +
"<html><head><title></title>"+
"<style type=\"text/css\">" +
"'body {color:#FFFFFF;background-color:#000000;font-size: 10pt}'" +
"</style>" +
"</head>" +
"<body>" +
"%s" +
"</body></html>";
String textHtml = String.format(Constants.HTML_FORMAT,encoding);
wv.setBackgroundColor(Color.BLACK);
wv.loadDataWithBaseURL(null, textHtml, "text/html","utf-8", null);
try this hopefully you will get your required result.