java - How to get the Html body content only from the current url loaded in webview android -
i beginner android developer. need develop android project. there task load website url webview , content of html tag more time tried source code content webview can't correct solution internet please give solution develop project
that below ..
public class htmlviewactivity extends activity {
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); final webview webview = (webview) findviewbyid(r.id.webview1); webview.getsettings().setjavascriptenabled(true); webview.addjavascriptinterface(new myjavascriptinterface(this), "htmlviewer"); webview.setwebviewclient(new webviewclient() { @override public void onpagefinished(webview view, string url) { webview.loadurl("javascript:window.htmlviewer.showhtml" + "(document.getelementsbytagname('body')[0].innerhtml);"); } }); webview.loadurl("http://www.google.com"); } class myjavascriptinterface { private context ctx; myjavascriptinterface(context ctx) { this.ctx = ctx; } public void showhtml(string html) { toast.maketext(getapplicationcontext(), html, toast.length_long).show(); new alertdialog.builder(ctx).settitle("html code").setmessage(html) .setpositivebutton(android.r.string.ok, null).setcancelable(false).create().show(); } }
}
Comments
Post a Comment