I have String with html format, not url, that send through from api. Those include image and bootstrap css. I would like to download those things to show in offline including image and css to show right format.
Is there any library to download html string content?
All You Have to do is get your Json Data convert Json to String json.toString();
and pass it to data=json.String();
and check if data is already stored or not in Shared Preferences
DataBaseHelper DB;
if(DB.getHTMLStoredData(context)){
data=DB.getHTMLStoredData(context)
}else{
data=json.String();
}
//data == html data which you want to load
WebView webview = (WebView)this.findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadDataWithBaseURL("", data, "text/html", "UTF-8", "");
Related
I want to display video in android app.
The link of video is blob link so that i think i need use webview to display it.
How to implement it?
WebView support loading HTML data from string. So following code is possible.
String videoBlobLinkUrl = "data:video/mp4;base64,[video base64-encoded data ..]";
String videoBlobMime = "video/mp4";
String videoHtml = "<html><body><video><source type=\""+videoBlobMime+"\" src=\""+ videoBlobLinkUrl +"\"></video></body></html>";
webview.loadData(videoHtml, "text/html", null);
I want to implement a Rich text editor by using a webview in android. Content can be loaded by using a HTML file (which resides in assets) without any problem. But if user has edited the content of the webview (with all the formatting), I need to get the modified content as a HTML string and save it in the database. How can I do this?
I tried in many ways but it seems that we need to pass a URL to get the content of the webview. But after editing the webview content, how can we get the edited URL? or current updated webview content to HTML formatted string?
Using below code I made editable web view.
String msgBody = "<html>\n"+
"<body>\n"+
"<div id=\"content\" contenteditable=\"true\" style=\"font-family:Helvetica;font-size:14px\">" + a +" </div>\n"+
"</body>"+
"</html>";
// wbview = (WebView)this.findViewById(R.id.wbview);
wbView.getSettings().setJavaScriptEnabled(true);
wbView.loadDataWithBaseURL("", msgBody, "text/html", "UTF-8", "");
wbView.setHorizontalScrollBarEnabled(true);
wbView.setVerticalScrollBarEnabled(true);
In iOS we can get it easily by using below code line.
NSString* html=[_tbEmail.webView stringByEvaluatingJavaScriptFromString:#"document.getElementsByTagName('body')[0].innerHTML"];
I need to load the HTML content which includes, remote image src.
So I wrote a string like below
String trl = "<html><body><a id=\"example1\" href=\"http://example.com/android/images/4252054277_f0fa91e026.jpg\"><img alt=\"example1\" src=\"http://example.com/android/images/4252054277_f0fa91e026_m.jpg\" /></a></body></html>";
I then load with the below URL
webview.loadDataWithBaseURL("", trl, "text/html", "UTF-8", "");
It's showing the text i.e "example-1" instead of showing the image from the URL. I double check the location of images too. they are valid.
What am I doing wrong?
I have an Android app, which contains a WebView, and I would like to display in it not a webpage, but only a div from that webpage. I should mention that I do not have access to that page.
I would recommend Jsoup. It's larger than tagsoup but provides inbuilt functionality to pull the HTML from the URL and is super easy to use. For example if you want to pull a div with id example you would do the following:
Document doc = Jsoup.connect(url).get();
Elements ele = doc.select("div#example");
Then to load the HTML you've extracted into your web view you would do:
String html = ele.toString();
String mime = "text/html";
String encoding = "utf-8";
webView.loadData(html, mime, encoding);
You'll need to load the HTML of the page yourself, extract the div contents and pass it to the WebView as a string. You may find an HTML parser library (e.g. tagsoup) useful for this.
I want to display my data's in a html page, I make a static html page in assest folder .but don't know how to insert my data's in that html page programmatically.
You'll need to have a WebView in your activity. Then load the html into the webview, here are some instructions.
Loading an html page from an asset is relatively simple:
WebView webView = (WebView)view.findViewById(R.id.myWebView);
webView.loadUrl("file:///android_asset/index.html");
But to programatically alter the content of the page you'd have to first read the asset file into a string, insert your data with a string replace, or use java.text.MessageFormat.
Here's the code to get an inputstream from an asset:
AssetManager mgr = this.getAssets();
InputStream is = mgr.open("index.html");
BufferedInputStream in = new BufferedInputStream(is);
// read the contents of the file
Once you have your html string populated, you can programmatically set the content of the webview:
webView.loadData(htmlString, "text/html", "UTF-8");