Monday, June 10, 2013

[Android Tips]: Getting users to +1 your app

In order to improve your application's ranking in the Google Play store, you should get users to +1 your app.  You can do this using GooglePlayServices and the PlusOneButton Android UI element.  Here is a simple layout file that includes the plus one button:

[code]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dip"
android:background="@android:color/black" >

<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
plus:size="tall"
plus:annotation="inline" />

</LinearLayout>
[/code]

It creates the following User Interface Component:
google_plus_button_layout

 

 

Then in your MainActivity's onResume method you can check to see if the layout is visible and then initialize the button:

[code]
@Override
protected void onResume() {
super.onResume();

if (plusLayout.getVisibility() == View.VISIBLE) {
// Refresh the state of the +1 button each time the activity receives focus.
mPlusOneButton.initialize(mPlusClient, APP_URL, PLUS_ONE_REQUEST_CODE);
}

}

[/code]

 

The APP_URL is the link to your app on the Google Play Store

The PLUS_ONE_REQUEST_CODE is any integer value >= 0

Building on the AppRater code base, you can modify it to set a flag when you want to show the plus_button_layout to the user, similar to the following:

[code]

public class AppRater {
private final static int DAYS_UNTIL_PROMPT = 1;
private final static int LAUNCHES_UNTIL_PROMPT = 4;

public static void app_launched(Context mContext) {
SharedPreferences prefs = mContext.getSharedPreferences(PreferenceConstants.PREFERENCE_NAME, Activity.MODE_PRIVATE);
if (prefs.getBoolean(PreferenceConstants.PREFERENCE_SHOW_PLUS, false)) { return ; }

SharedPreferences.Editor editor = prefs.edit();

// Increment launch counter
long launch_count = prefs.getLong("launch_count", 0) + 1;
editor.putLong("launch_count", launch_count);

// Get date of first launch
Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
if (date_firstLaunch == 0) {
date_firstLaunch = System.currentTimeMillis();
editor.putLong("date_firstlaunch", date_firstLaunch);
}

// Wait at least n days before opening
if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= date_firstLaunch +
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
editor.putBoolean(PreferenceConstants.PREFERENCE_SHOW_PLUS, true);
editor.commit();
return ;
}
}

editor.commit();
}

}

[/code]



*** Download our first game: Word Crank today for free: Available on iOS and Android***

1 comment: