Friday, 15 February 2013

Integrating Disqus comment in Android App -



Integrating Disqus comment in Android App -

i had made application help of next links, when login disqus entering comment, need refresh page, shows logged in , can come in comment. using html snippet rather php one. links referring are:-

http://globeotter.com/blog/disqus-android-code/

http://globeotter.com/blog/disqus-login-and-logout/

my code below:-

public class mainactivity extends activity { webview webdisqus; string smyurl; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); string htmlcomments = gethtmlcomment("<mywebsite_disqus_id>", "<mywebsite_shortname>"); smyurl="mywebsites_url"; webdisqus = (webview) findviewbyid(r.id.disqus); // set disqus websettings websettings2 = webdisqus.getsettings(); websettings2.setjavascriptenabled(true); websettings2.setbuiltinzoomcontrols(true); webdisqus.requestfocusfromtouch(); webdisqus.setwebviewclient(new mywebviewclient(htmlcomments, "text/html", null, smyurl)); webdisqus.setwebchromeclient(new webchromeclient()); webdisqus.loaddata(htmlcomments, "text/html", null); } public string gethtmlcomment(string idpost, string shortname) { homecoming "<div id='disqus_thread'></div>" + "<script type='text/javascript'>" + "var disqus_identifier = '" + idpost + "';" + "var disqus_shortname = '" + shortname + "';" + " (function() { var dsq = document.createelement('script'); dsq.type = 'text/javascript'; dsq.async = true;" + "dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';" + "(document.getelementsbytagname('head')[0] || document.getelementsbytagname('body')[0]).appendchild(dsq); })();" + "</script>"; } }

and mywebview class follows:-

`

public class mywebviewclient extends webviewclient {` private string html_comments, stype, obj, smyurl; public mywebviewclient(string htmlcomments, string string, string object, string url) { // todo auto-generated constructor stub html_comments=htmlcomments; stype=string; obj=object; smyurl=url; } @override public void onpagestarted(webview view, string url, bitmap favicon) { log.i("page started", url); } @override public void onreceivederror(webview view, int errorcode, string description, string failingurl) { log.i("disqus error", "failed: " + failingurl + ", error code: " + errorcode + " [" + description + "]"); } public void onpagefinished(webview view, string url) { if(url.indexof("logout")>-1 || url.indexof("disqus.com/next/login-success")>-1 ){ view.loaddata(html_comments, stype, obj); } if(url.indexof("disqus.com/_ax/twitter/complete")>-1||url.indexof("disqus.com/_ax/facebook/complete")>-1||url.indexof("disqus.com/_ax/google/complete")>-1){ view.loaddata(html_comments, stype, obj); } if(url.indexof(smyurl+"/login.php")>-1){ view.loaddata(html_comments,stype, obj); } } }`

can tell me should not refresh page whenever login , logout disqus through webview of activity.

well above code runs on android devices. problem occurs if run on emulator, emulator slow compared devices...

android disqus

No comments:

Post a Comment