{"id":43,"date":"2012-12-26T23:15:31","date_gmt":"2012-12-26T22:15:31","guid":{"rendered":"http:\/\/globeotter.com\/blog\/?p=43"},"modified":"2014-01-16T18:25:24","modified_gmt":"2014-01-16T17:25:24","slug":"disqus-android-code","status":"publish","type":"post","link":"http:\/\/globeotter.com\/blog\/disqus-android-code\/","title":{"rendered":"DISQUS on Android"},"content":{"rendered":"<p>Here we thought we&#8217;d give you a quick tutorial on how to integrate DISQUS \u00a0on Android. The implementation in a webpage is fairly straightforward and not too difficult in Android either. Since we just released a version of our Votter App with these comments enabled we thought we&#8217;d share some of the details behind the code. We&#8217;ll detail out a scenario using an android xml layout, android class and a simple php page. Before starting you should have already created an android app and be able to deploy it. \u00a0A hosting account will also be needed for the php component of our walk through. If you have not done this there are many tutorials over on the google android developers webpage.<\/p>\n<p>To start with make sure your app has internet\u00a0permissions\u00a0\u00a0&lt;uses-permission android:name=&#8221;android.permission.INTERNET&#8221;&gt;&lt;\/uses-permission&gt; and you have signed up for <a title=\"DISQUS\" href=\"http:\/\/disqus.com\/for-websites\/\" target=\"_blank\">DISQUS<\/a> and set up your site. It is good to have some familiarity with the system so try setting up a basic comment page on your webpage first so you know your setup in correct.<\/p>\n<p>Start with making a layout called disqus.xml. Since we will be setting up our php \u00a0page in a moment, we will include a WebView object. The most frustrating part of most Android development is testing different\u00a0resolutions\u00a0and orientations. Thankfully by using WebView, we let WebView do all the\u00a0heavy\u00a0lifting\u00a0in this area.\u00a0Place whatever elements you like in the xml file but place a WebView on the bottom. \u00a0For most layouts that might have extensive comments, you will likely want to place your whole page in a ScrollView. \u00a0Using \u00a0fill_parent \u00a0is a good idea here if it is just going to be tagged onto the bottom of the layout.<\/p>\n<h2>disqus.xml<\/h2>\n<pre class=\"brush: plain; highlight: [19,20,21,22]; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\r\n\r\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\r\n android:orientation=&quot;vertical&quot;\r\n android:layout_width=&quot;fill_parent&quot;\r\n android:layout_height=&quot;wrap_content&quot; &gt;\r\n\r\n&lt;ScrollView\r\n android:layout_width=&quot;match_parent&quot;\r\n android:layout_height=&quot;match_parent&quot; &gt;\r\n\r\n&lt;LinearLayout\r\n android:layout_width=&quot;match_parent&quot;\r\n android:layout_height=&quot;match_parent&quot;\r\n android:orientation=&quot;vertical&quot; &gt;\r\n\r\n\/\/ INSERT all your other GUI objects on top of the comments here\r\n\r\n&lt;WebView xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\r\n android:id=&quot;@+id\/disqus&quot;\r\n android:layout_width=&quot;fill_parent&quot;\r\n android:layout_height=&quot;fill_parent&quot; \/&gt;\r\n\r\n&lt;\/LinearLayout&gt;\r\n&lt;\/ScrollView&gt;\r\n&lt;\/LinearLayout&gt;\r\n<\/pre>\n<p>Once you have your layout how you like, it is best to go ahead and set up a php page on your server. This page will essentially be blank but setup the same way any old DISQUS thread would be set up. The difference being we will pass the disqus_identifier in through the URL. With the exception of line 6 this is taken from the DISQUS installation guide. So in case of an update to the API, just follow their guide. Don&#8217;t forget to add the shortname for your disqus application.<\/p>\n<h2>showcomments.php<\/h2>\n<pre class=\"brush: plain; highlight: [6]; title: ; notranslate\" title=\"\">\r\n&lt;div id=&quot;disqus_thread&quot;&gt;&lt;\/div&gt;\r\n&lt;script type=&quot;text\/&lt;span class=&quot;&gt;\r\n\r\n\/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * *\/\r\n var disqus_shortname = '&lt;shortname&gt;'; \/\/ required: replace example with your forum shortname\r\n var disqus_identifier = '&lt;?php echo $_GET&#x5B;'disqus_id']; ?&gt;';\r\n\r\n\/* * * DON'T EDIT BELOW THIS LINE * * *\/\r\n (function() {\r\n var dsq = document.createElement('script'); dsq.type = 'text\/javascript'; dsq.async = true;\r\n dsq.src = 'http:\/\/' + disqus_shortname + '.disqus.com\/embed.js';\r\n\r\n(document.getElementsByTagName('head')&#x5B;0] || document.getElementsByTagName('body')&#x5B;0]).appendChild(dsq);\u00a0})();\r\n &lt;\/script&gt;\r\n &lt;noscript&gt;\r\n\r\nPlease enable JavaScript to view the &lt;a href=&quot;http:\/\/disqus.com\/?ref_noscript&quot;&gt;comments powered by Disqus.&lt;\/a&gt;\r\n\r\n&lt;\/noscript&gt;\r\n\r\n&lt;a href=&quot;http:\/\/disqus.com&quot; class=&quot;dsq-brlink&quot;&gt;comments powered by &lt;span class=&quot;logo-disqus&quot;&gt;Disqus&lt;\/span&gt;&lt;\/a&gt;\r\n\r\n<\/pre>\n<p>Ok now that both\u00a0components\u00a0are setup we just need to link them together in our activity. To do this just load your xml layout(disqus.xml) in your Activity (Disqus.java). To load the comments we will simply do it onCreate. Instantiate your WebView and assign what WebSettings your wish to it. In line 27 you can see to load the comments we will just call our php file with a URL parameter that will be the disqus_identifier. You can store this in a variable or have it static depending on how many forums or comment threads you have.<\/p>\n<h2>Disqus.java<\/h2>\n<pre class=\"brush: plain; highlight: [27]; title: ; notranslate\" title=\"\">&lt;\/pre&gt;\r\npublic abstract class Disqus extends Activity\r\n{\r\nprivate WebView webDisqus;\r\n\r\nprotected void onCreate(Bundle savedInstanceState)\r\n{\r\n\r\n\/\/set layout to disqus xml\r\n\r\nsetContentView (R.layout.disqus);\r\n\r\nwebDisqus = (WebView) findViewById(R.id.disqus);\r\n \/\/set up disqus\r\n WebSettings webSettings2 = webDisqus.getSettings();\r\n\r\nwebSettings2.setJavaScriptEnabled(true);\r\n\r\nwebSettings2.setBuiltInZoomControls(true);\r\n\r\nwebDisqus.requestFocusFromTouch();\r\n\r\nwebDisqus.setWebViewClient(new WebViewClient());\r\n\r\nwebDisqus.setWebChromeClient(new WebChromeClient());\r\n\r\nwebDisqus.loadUrl(&quot;http:\/\/&lt;PATH TO WEB SERVER&gt;\/showcomments.php?disqus_id=&quot;+&lt;disqus thread id&gt;);\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p>That is it for loading DISQUS on Android. If you have any questions or suggestions leave them in the comments below. If you&#8217;d like to see a demo of this first, check out the <a title=\"Votter App\" href=\"https:\/\/play.google.com\/store\/apps\/details?id=otter.votter\" target=\"_blank\">Votter App<\/a> on Google Play. \u00a0If you want more code samples of different techniques used in Votter or any of the GlobeOtter Apps just send us a message or leave a comment below and we will try to write up a\u00a0walk through.<\/p>\n<h2>Update<\/h2>\n<p>To address the login and logout issues we were seeing we added a<a title=\" blog entry\" href=\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/\" target=\"_blank\"> blog entry<\/a> here\u00a0<strong>http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/.\u00a0<\/strong> You can also check out a full implementation of this in our new App the <a title=\"Daily Forum\" href=\"https:\/\/play.google.com\/store\/apps\/details?id=otter.forum\" target=\"_blank\">Daily Forum<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here we thought we&#8217;d give you a quick tutorial on how to integrate DISQUS \u00a0on Android. The implementation in a webpage is fairly straightforward and not too difficult in Android either. Since we just released a version of our Votter App with these comments enabled we thought we&#8217;d share some of the details behind the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[6,11],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-code-sample","category-disqus","tag-code","tag-disqus","bubble-left"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>DISQUS Android Code Walkthrough - GlobeOtter<\/title>\n<meta name=\"description\" content=\"Code and walkthrough for the DISQUS comment system on Android OS. Code samples given for php, xml, and java files.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/globeotter.com\/blog\/disqus-android-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DISQUS Android Code Walkthrough - GlobeOtter\" \/>\n<meta property=\"og:description\" content=\"Code and walkthrough for the DISQUS comment system on Android OS. Code samples given for php, xml, and java files.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/globeotter.com\/blog\/disqus-android-code\/\" \/>\n<meta property=\"og:site_name\" content=\"GlobeOtter\" \/>\n<meta property=\"article:published_time\" content=\"2012-12-26T22:15:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-01-16T17:25:24+00:00\" \/>\n<meta name=\"author\" content=\"ndgreen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@globeotter\" \/>\n<meta name=\"twitter:site\" content=\"@globeotter\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ndgreen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/globeotter.com\/blog\/disqus-android-code\/\",\"url\":\"http:\/\/globeotter.com\/blog\/disqus-android-code\/\",\"name\":\"DISQUS Android Code Walkthrough - GlobeOtter\",\"isPartOf\":{\"@id\":\"http:\/\/globeotter.com\/blog\/#website\"},\"datePublished\":\"2012-12-26T22:15:31+00:00\",\"dateModified\":\"2014-01-16T17:25:24+00:00\",\"author\":{\"@id\":\"http:\/\/globeotter.com\/blog\/#\/schema\/person\/31fcba120c14e75da9dc801136a6ce5b\"},\"description\":\"Code and walkthrough for the DISQUS comment system on Android OS. Code samples given for php, xml, and java files.\",\"breadcrumb\":{\"@id\":\"http:\/\/globeotter.com\/blog\/disqus-android-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/globeotter.com\/blog\/disqus-android-code\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/globeotter.com\/blog\/disqus-android-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/globeotter.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"disqus code on android\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/globeotter.com\/blog\/#website\",\"url\":\"http:\/\/globeotter.com\/blog\/\",\"name\":\"GlobeOtter\",\"description\":\"GlobeOtter Development and News\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/globeotter.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/globeotter.com\/blog\/#\/schema\/person\/31fcba120c14e75da9dc801136a6ce5b\",\"name\":\"ndgreen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/globeotter.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/80e4d0ae2e6044a1c6244388de171b5e5a488d004ffeb96dd914407ebef4b944?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/80e4d0ae2e6044a1c6244388de171b5e5a488d004ffeb96dd914407ebef4b944?s=96&d=mm&r=g\",\"caption\":\"ndgreen\"},\"sameAs\":[\"http:\/\/www.nathangreen.com\"],\"url\":\"http:\/\/globeotter.com\/blog\/author\/ndgreen\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DISQUS Android Code Walkthrough - GlobeOtter","description":"Code and walkthrough for the DISQUS comment system on Android OS. Code samples given for php, xml, and java files.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/globeotter.com\/blog\/disqus-android-code\/","og_locale":"en_US","og_type":"article","og_title":"DISQUS Android Code Walkthrough - GlobeOtter","og_description":"Code and walkthrough for the DISQUS comment system on Android OS. Code samples given for php, xml, and java files.","og_url":"http:\/\/globeotter.com\/blog\/disqus-android-code\/","og_site_name":"GlobeOtter","article_published_time":"2012-12-26T22:15:31+00:00","article_modified_time":"2014-01-16T17:25:24+00:00","author":"ndgreen","twitter_card":"summary_large_image","twitter_creator":"@globeotter","twitter_site":"@globeotter","twitter_misc":{"Written by":"ndgreen","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/globeotter.com\/blog\/disqus-android-code\/","url":"http:\/\/globeotter.com\/blog\/disqus-android-code\/","name":"DISQUS Android Code Walkthrough - GlobeOtter","isPartOf":{"@id":"http:\/\/globeotter.com\/blog\/#website"},"datePublished":"2012-12-26T22:15:31+00:00","dateModified":"2014-01-16T17:25:24+00:00","author":{"@id":"http:\/\/globeotter.com\/blog\/#\/schema\/person\/31fcba120c14e75da9dc801136a6ce5b"},"description":"Code and walkthrough for the DISQUS comment system on Android OS. Code samples given for php, xml, and java files.","breadcrumb":{"@id":"http:\/\/globeotter.com\/blog\/disqus-android-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/globeotter.com\/blog\/disqus-android-code\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/globeotter.com\/blog\/disqus-android-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/globeotter.com\/blog\/"},{"@type":"ListItem","position":2,"name":"disqus code on android"}]},{"@type":"WebSite","@id":"http:\/\/globeotter.com\/blog\/#website","url":"http:\/\/globeotter.com\/blog\/","name":"GlobeOtter","description":"GlobeOtter Development and News","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/globeotter.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/globeotter.com\/blog\/#\/schema\/person\/31fcba120c14e75da9dc801136a6ce5b","name":"ndgreen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/globeotter.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/80e4d0ae2e6044a1c6244388de171b5e5a488d004ffeb96dd914407ebef4b944?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/80e4d0ae2e6044a1c6244388de171b5e5a488d004ffeb96dd914407ebef4b944?s=96&d=mm&r=g","caption":"ndgreen"},"sameAs":["http:\/\/www.nathangreen.com"],"url":"http:\/\/globeotter.com\/blog\/author\/ndgreen\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":85,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":310,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions\/310"}],"wp:attachment":[{"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}