Disqus Login and Logout in Android

Disqus login and logout features as described in the previous blog entry on Disqus (http://globeotter.com/blog/disqus-android-code/) do not work as intended in the latest updates. Currently if you followed the Code the login will stay busy and the page has to be refreshed. You can see the busy signal in the screenshot below. To get rid of it you have to change Activities and come back to the Disqus page (in which you are auto logged in).  After looking into it a bit, we found a nice work around for these issues.

Disqus login and logout created a busy signal in this screenshot

If you would like to see how the code works you can look at our new App we made to Demo the functionality, The Daily Forum https://play.google.com/store/apps/details?id=otter.forum

The solution to the Disqus login and logout issues are contained in the WebViewClient in Android. It is not picking up the redirect and refreshing the page in the javascript. To address this we will need a new class that extends WebViewClient

MyWebViewClient.java

public class MyWebViewClient extends WebViewClient {

private String myUrl;
 public MyWebViewClient(String _myURL) {
 // TODO Auto-generated constructor stub
 myUrl=_myURL;

 }
 @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.loadUrl(myUrl);

 }
 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.loadUrl("YOUR_URL/login.php");

 }
 if(url.indexOf("YOUR_URL/login.php")>-1){
 view.loadUrl(myUrl);
}
}
}

There are a few key features of this code. First it is listening for the Twitter,Facebook, and Google Plus login code. Your WebViewClient will now be looking for this URL “disqus.com/_ax”. When it detects this we send it to a blank URL login.php. This login page does nothing, we only use it so we can detect that the 3rd party login was successful. Second, after we have either detected a 3rd party login (via login.php) or have been logged in via disqus (“disqus.com/next/login-success”) we refresh our URL (this is the URL passed in that your disqus page was using). Third, the logout code is quite simple. When a logout is detected simply refresh the url as well.

Next we need to actually call this class. We will use the same Disqus.java class as the previous blog entry on Disqus, but this time we will call MyWebViewClient

Disqus.java

</pre>
public abstract class Disqus extends Activity
{
private WebView webDisqus;

protected void onCreate(Bundle savedInstanceState)
{

//set layout to disqus xml
String url="http:///showcomments.php?disqus_id="+insert disqus thread is here;
setContentView (R.layout.disqus);

webDisqus = (WebView) findViewById(R.id.disqus);
 //set up disqus
 WebSettings webSettings2 = webDisqus.getSettings();

webSettings2.setJavaScriptEnabled(true);

webSettings2.setBuiltInZoomControls(true);

webDisqus.requestFocusFromTouch();

//set to the new WebViewClient Class
webDisqus.setWebViewClient(new MyWebViewClient(url));

webDisqus.setWebChromeClient(new WebChromeClient());

webDisqus.loadUrl(url);

}

}

We hope this helps if you were struggling with the Disqus login and logout in Android. Let us know if it works for you. If you get a chance check out the Daily Forum and leave us a review!

Android Advertising Options

I am teaching a seminar on Android programming and a common question comes up on how to make money with an App. It is the conventional wisdom that IPhone apps sell and Android Apps do not. This is somewhat true. Android apps have been forced to make money through less than beautiful ways. Mainly developers have used banner ads.

There has been a few attempts to further this in the past that were shut down in the previous Google Play Update, namely:

  • Push Ads: Theses ads placed advertisements in your status bar even when the app was not running. OF course, this was quite profitable for companies but really angered the app users.
  • Home Screen Icons: The ads place an icon on the home screen when the App installed that linked to a page of advertisements. This was mainly used through the Leadbolt ad system (which does other types of ads as well).

Both of these types were highly profitable but left users confused on where the ads were coming from. Because of this Google Play as banned both types.

This leaves developers with one main options, the old banner ad. There are an endless amount of companies who offer banner ads. My personal favorite for Apps in the USA is the Amazon Mobile Ad sdk. The most popular ad network is Admob by Google. Admob has one serious problem however, it is likely you will be banned and you will receive zero reasons why. Google famously will not tell you why you are banned. One day you account is disabled and all the money you have collected is gone. For this reason I cannot suggest AdMob.  A quick search on google will give you plenty of alternatives. My suggestion is to pick an ad company that has higher ad placement in the country your App does well with (i.e. Amazon for the USA).

Outside of banner ads you have other methods of monetization such as in store purchases. I will go over these in a later post.

If you have an ad company you like feel free to add it to the Disqus comment page below.

Social Voting Platform, Votter, has a Quarter Million Votes in March

Things have been very busy with the Votter Team in March. We reach a milestone, having a quarter million votes cast in a single month. With the new growth came many new poll types. To better handle and categorize all your polls we added a Fashion, Foodie, Am I pretty, Pets and Animals, Follow Me, and Fitness categories. By far the most popular have been the “Am I Pretty?” and the “Fashion” Categories.

Our two most popular polls were a combination of social awareness and fashion! This Poll about smoking started one of our largest Disqus debates as of yet!

With Prom season coming up we are seeing many Fashion polls like the second and they remain popular. The dress poll was the second most popular poll of the month.

If you have an event coming up head on over to the Android app  and submit a poll today.

Votter Release: Now with Image Polls and Two New Categories

A little update about the new Votter release that allows Image Polls. With this update you can include a photo with your poll options. With the  image polls feature we have also opened up two new categories. First, we are calling “Where in the world?”. For this upload a photo of your location and give us a few options to guess what country you are in. When the poll closes remember to come back and tell us the correct answer  in the Disqus comments section. The second new category will be “fashion”. We have already had submission for photos of outfits and whether or not to wear them. We think these two categories will be a fun diversion from some of the political topics which have been popular recently. We hope you enjoy the new categories.

With images comes some additional functionality. We have upgraded our “mature” filtering options so that it covers all functionality in the App. If you would like “mature” polls turned off please use the android options panel to toggle this option. All polls are subject to approval so with this off you should only see more “family friendly” polls to vote on.

votter image poll

Image of the new Where in the World Image Polls on Votter

Other than this feature we have fixed a few lingering bugs that had the program acting in ways not intended.  Remember to check your language options to make sure you are receiving polls in other languages if you want them. We hope you like the new image polls and category types and look forward to seeing the image polls you submit in the two new categories.

Enjoy and get Vottering,

The Votter Team

Tracking Apps Across Countries

Tracking Apps on Android

If you are like us, you are having trouble tracking apps across countries. You have made a great app but you don’t know if anyone is seeing it. Each country has a different Google Play view. If you want alot of downloads you need to make a “top” list on Google Play or another market. Like most curious developers you probably load up Google Play and look at the top lists. The problem is you are only seeing the top list for the country you are in. Sometimes you develop an App for a country you are not in. For instance we have a Road Sign App for Indonesia, there is no way for us to tell from our current country whether we have made an impact other than looking at our total downloads and guessing. There are a few options we have found but I will describe the two we use most often.

AppAnnie

AppAnnie started out tracking apps on IOS but has recently moved to Android. It only covers Google play but it does track across 46 countries (Indonesia being one of them). AppAnnie will track your Google Play sales, ranks, downloads, and reviews.It comes with a nice graphical representation of all information. It connects via your developer account so all your apps will be imported so you can see how they compare against each other.

Tracking Apps on Android with AppAnnie

Tracking Android Apps on AppAnnie

Sometimes you will be surprised how your apps do. For instance we briefly started having out apps rank in Chile. The reason I don’t know but it did give us a quick download spike and indicated to us that maybe we need to use some Spanish localization for our apps.

Distimo

Distimo on the other hand tracks apps in multiple markets. As I write this we use Distimo to track apps in Amazon, Getjar, Google Play, and Samsung app stores.  The interface is not as “beautiful” as AppAnnie but with more complexity comes more data. Our apps vary greatly among the different app stores so this is an invaluable resource. In addition to the multiple android app stores, you can add your “competitors” to your account and review how you do against them in different categories. Additionally you can track your ad revenue across multiple companies as well, not just the basic admob.

In conclusion, I think both are needed. While Distimo does duplicate the information given to us from AppAnnie. AppAnnie is much quicker to look at and get a daily idea of how your apps are doing, even if it is only on Google Play. When you need to get down to the nitty gritty then I suggest digging through Distimo’s data but on a daily basis AppAnnie suffices.

If you have something else you like to use for tracking apps on Android, leave us a comment in the Disqus forum below.

Android App Reviews through Prompts

A common problem and question with new developers is how to get android app reviews. You have put out a great app and can’t figure out why no one has left you the 5 star review you incredibly deserve. Maybe you need more users? Well you don’t get high up in the Google Play store without many reviews. And here is the Android Chicken and Egg problem: You need reviews to get users and you need users to get reviews.

One path some developers go to is paying for reviews. This is almost always a bad idea. While you might get a spike in reviews, you will eventually be found out and those reviews will slowly disappear.  This approach also leaves out the most important part of the review, which is good user feedback. As a start-up developer you will want to make lots of small incremental changes to your App. Often the best source of what should be in these changes comes from your users (after all they are who you want to please). Early on in our USA Road Sign Test game we overlooked one critical feature. We treated the App like a game and not an educational test. We didn’t notice until we got this review “wish it would tell you the signs that you got incorrect”. Of Course! Seems logical enough but as developers you will often miss simple things.  If you use a system to get reviews that are “less than honest” you are missing out on this valuable cycle.

If you just wait for reviews to come in you may be waiting for a while. The next and the best (in our opinion) option is to prompt users for reviews.  But word of caution, if you prompt users constantly and without regard to their experience you will do more harm than good. You do not want angry users reviewing your app. So forcing your users to visit your Google Play Page without options to dismiss  or never be prompted again will only end with everyone crying.

Two main things you want to keep in mind are 1) How long has the user had the App 2) How many times has the user launched the App . This ensures that the user that reviews you is a “Fan” and probably won’t mind being prompted for a review.  A third option but not one that we use to to check to see if the App has ever crashed.  If it has crashed don’t prompt the user for a review. If you want this approach you can use libraries such as AppRate. For our USA Road Sign Test game we use an implementation similar to this AppRater. It allows the developer to specify the days and launches to prompting (we usually user 3 for both). We have added some additional functionality to our code to allow users to ignore the prompt forever or just once. We keep track of this using SharedPreferences.

AppRater send you to a market of your choosing. Not all users use Google Play so we normally make multiple builds for each marketplace. We use a global market variable that handles this.

//make this a global in your App so you only set it once

private int market=0; //0=Google Play 1=Amazon 2=SlideME

//Make this method in your main Activity class (prefer to be extendable) so it can be called anywhere

public String getMarketPlace(){

switch(market){
 case 0:
 return "https://market.android.com/details?id=<package>";
 case 1:
 return "http://www.amazon.com/gp/mas/dl/android?p=<package?";
 case 2:
 return "http://slideme.org/application/<name>";
 }

return null;

}

Now does it work? Well for USA Road Sign Test we only had 5 reviews after the first few months. Once we started prompting we went up fast in the Google Plat rankings. We now a few months later have 40+ reviews which are mostly positive.None of the reviews have complained about being prompted once for a review.

You probably want to add some more functionality for adding reviews into your program. For instance we also have a link in our options menu that allows the user to share the MarketPlace Address with their social networks using the same method as above.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
 MenuInflater inflater = getMenuInflater();
 inflater.inflate(R.menu.my_menu, menu);
 return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
 // Handle item selection
switch (item.getItemId()) {
case R.id.share:
 Intent shareIntent = new Intent(Intent.ACTION_SEND);
 shareIntent.setType("text/plain");
 shareIntent.putExtra(Intent.EXTRA_TEXT,"Check out this app! "+getMarketPlace());
 shareIntent.putExtra(Intent.EXTRA_SUBJECT,"Check out this app!");
 startActivity(Intent.createChooser(shareIntent,"Share..."));
 return true;
return super.onOptionsItemSelected(item);
 }
}

This is a good base to get you up and going for more Android App Reviews. If you have some other options or suggestions please leave them in our DISQUS comments section.

DISQUS on Android

Here we thought we’d give you a quick tutorial on how to integrate DISQUS  on 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’d share some of the details behind the code. We’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.  A 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.

To start with make sure your app has internet permissions  <uses-permission android:name=”android.permission.INTERNET”></uses-permission> and you have signed up for DISQUS 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.

Start with making a layout called disqus.xml. Since we will be setting up our php  page in a moment, we will include a WebView object. The most frustrating part of most Android development is testing different resolutions and orientations. Thankfully by using WebView, we let WebView do all the heavy lifting in this area. Place whatever elements you like in the xml file but place a WebView on the bottom.  For most layouts that might have extensive comments, you will likely want to place your whole page in a ScrollView.  Using  fill_parent  is a good idea here if it is just going to be tagged onto the bottom of the layout.

disqus.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" >

<ScrollView
 android:layout_width="match_parent"
 android:layout_height="match_parent" >

<LinearLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >

// INSERT all your other GUI objects on top of the comments here

<WebView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/disqus"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" />

</LinearLayout>
</ScrollView>
</LinearLayout>

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’t forget to add the shortname for your disqus application.

showcomments.php

<div id="disqus_thread"></div>
<script type="text/<span class=">

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
 var disqus_shortname = '<shortname>'; // required: replace example with your forum shortname
 var disqus_identifier = '<?php echo $_GET['disqus_id']; ?>';

/* * * DON'T EDIT BELOW THIS LINE * * */
 (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>
 <noscript>

Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a>

</noscript>

<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

Ok now that both components are 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.

Disqus.java

</pre>
public abstract class Disqus extends Activity
{
private WebView webDisqus;

protected void onCreate(Bundle savedInstanceState)
{

//set layout to disqus xml

setContentView (R.layout.disqus);

webDisqus = (WebView) findViewById(R.id.disqus);
 //set up disqus
 WebSettings webSettings2 = webDisqus.getSettings();

webSettings2.setJavaScriptEnabled(true);

webSettings2.setBuiltInZoomControls(true);

webDisqus.requestFocusFromTouch();

webDisqus.setWebViewClient(new WebViewClient());

webDisqus.setWebChromeClient(new WebChromeClient());

webDisqus.loadUrl("http://<PATH TO WEB SERVER>/showcomments.php?disqus_id="+<disqus thread id>);

}

}

That is it for loading DISQUS on Android. If you have any questions or suggestions leave them in the comments below. If you’d like to see a demo of this first, check out the Votter App on Google Play.  If 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 walk through.

Update

To address the login and logout issues we were seeing we added a blog entry here http://globeotter.com/blog/disqus-login-and-logout/.  You can also check out a full implementation of this in our new App the Daily Forum.

Votter Release : DISQUS comment system

Some may have noticed that both for this blog and thevotter.com we use the DISQUS comment system. We had originally started out with our own “Blotter” commenting system but it quickly became alot to monitor without all the features we would want. We had been users of the DISQUS  comment system on other sites such as CNN so we figured we’d give it a shot. The web setup took about 10 minutes and implementation took only about an hour to modify our php files to use their API. Not bad at all but it did leave use with two disjoint systems since our Android app still used our old Blotter system.

With this update the blotter system has been removed and DISQUS has been implemented within our Android App. Now the comments will sync between the web and the app. We hope everyone enjoys the new system as they can have same account for commenting across news sites and across apps. You can give the comment system a try right here in the blog by registering with any of the social networks. If you like it, please let us know.

For those who didn’t update in version 1.06, we now also have Facebook Login for android. This is using the newly released facebook android SDK last week. We hope this will reduce the amount of users who download the app but don’t register. Using this plugin users can login to our App without registering.  The Android code for this is a bit more complex than DISQUS. Hopefully when the SDK is out a bit longer some standard approaches will be available.  However, if readers are interested we can release our code for the login script.

When looking at the Google App store we only saw a handful of apps using the DISQUS comment system  so we may do a code segment in a few days to help those who want to implement a similar system in Android. Let us know in the comment section if you need the code or just the general approach.

If you haven’t downloaded Votter you can follow the Google Play link below


Android app on Google Play

Welcome

Welcome to the new blog for GlobeOtter and thevotter.com. We will be updating you on all our Android apps as well as updates to our polling results from thevotter.com and the Votter Android App. As a small development team we have had to innovate and integrate many different parts of our systems to work for both the web and for Android. We will be sharing tidbits of our android development and web development with you over time. We hope you find it useful and will link your own solutions to similar problems.

Welcome and stay tuned