How do you store an html page in a sqlite database in android? I tried to convert the html page into bytes array to store in database. Please help me how to store insert that into db and then open that load in webview...
Asked
Active
Viewed 2,821 times
1
-
why in a database, use a file – Diego Torres Milano Mar 28 '13 at 03:10
-
i need to save in db..Then i want to display it in webview – Mohan Viswa Mar 28 '13 at 03:11
-
what have you done so far? – JRowan Mar 28 '13 at 03:23
-
1"I need ..." doesn't sound as a good explanation – Diego Torres Milano Mar 28 '13 at 03:24
2 Answers
0
Don't convert to bytes. Store it as a string in the database- its just text. As for opening it in a webview- you would read it from the database and then call loadData() to load it into the webview.

Gabe Sechan
- 90,003
- 9
- 87
- 127
-
Look at this? http://stackoverflow.com/questions/7536797/storing-long-string-of-html-in-sqlite-database-causes-unknown-error – Kgrover Mar 28 '13 at 03:14
0
I too think the Converting to String is the best solution. Here am pasting some codes which may help you. Get the html in the string and save it to db.. (saving to db code is omitted)
private String getDownloadButtonOnly(String url){
HttpGet pageGet = new HttpGet(url);
ResponseHandler<String> handler = new ResponseHandler<String>() {
public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
HttpEntity entity = response.getEntity();
String html;
if (entity != null) {
html = EntityUtils.toString(entity);
return html;
} else {
return null;
}
}
};
pageHTML = null;
try {
while (pageHTML==null){
pageHTML = client.execute(pageGet, handler);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Pattern pattern = Pattern.compile("<h2>Direct Down.+?</h2>(</div>)*(.+?)<.+?>", Pattern.DOTALL);
Matcher matcher = pattern.matcher(pageHTML);
String displayHTML = null;
while(matcher.find()){
displayHTML = matcher.group();
}
return displayHTML;
}
// after retreiving string from db,
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
//load the data
webview.loadData(summary, "text/html", null);
check this out :- http://developer.android.com/reference/android/webkit/WebView.html