Take a rate, take a dialog!

Just made a small and quick component for Android.
It is a dialog that pop up after a certain number of day and app launches, to ask the user to rate the app in Google Play.
Eventually it can show a “More” button to display the other apps of the author in Google Play.



It is a subclass of DialogFragment and I also made a version with the Support Library (V4).

If you have any suggestions / opinions, please jot them down as comments in this post. 🙂

I tried to make this dialog to be easiest to use as possible.
So this post is also some sort of tutorial about using DialogFragment (or at least an attempt :-P).
It is open source, of course, with Apache License 2.0.

Please, use dialogs carefully, as they can worsen user experience.
Read this post of Juhani Lehtimäki for more.

In my opinion, a “rate me” feature can still be implemented in an app, as a part of an already existing view or existing dialog, as the About or the Changelog.

In my github repository, there are four projects:

  1. RateMeDialog (The “real” library project)
  2. RateMeDialogV4
  3. RateMeDialogTest
  4. RateMeDialogTestV4

V4 means that the project use the Support Library to let old versions of Android to run it.
The Test projects are there only as samples.

In the end if you want to support only Ice Cream Sandwich and above, then RateMeDialog is the project you have to use, otherwise choose RateMeDialogV4.

How to use

To use the dialog there are three steps to follow:

  1. Use the project as a library project. (In Eclipse, right click on your project, “Android”, in “Library” section choose “Add”)
  2. Change the value of RateMeDialog.APPTAG.
  3. Just call RateMeDialog.showRateMeDialog() accordingly.

    1. Changing RateMeDialog.APPTAG is very important, as RateMeDialog use SharedPreferences to store the user response (to show the dialog later, to never show it again, etc.)
      Customizing this variable will prevent your app to accidentally use the settings of other apps that may use (I hope so! :-)) this same class.

      I wrote the meaning of RateMeDialog.showRateMeDialog()‘s parameters in the comments, anyway here is a copy & paste:

      • ownerManagerFragmentManager of the owner, the entity from which we want to show a dialog.
      • publisherName – If null then the relative button will be removed from the dialog.
      • appPackageName – The app to rate.
      • title – The dialog title. For now the title is rendered as a separate TextView for more flexibility. If null then the relative View will be removed from the dialog.
      • total_days – Number of days to do before show this dialog. Pass < 0 along with total_launches < 0 to ignore RATEMEDIALOG_NEVER.
      • total_launches – Number of launches to do before show this dialog. Pass < 0 along with total_days < 0 to ignore RATEMEDIALOG_NEVER.
      • context – Normally it is the Activity from which you called this method.

      RateMeDialogActivity class of project RateMeDialogTest is self explanatory on how to practically use RateMeDialog.
      It is a simple app that shows the dialog automatically after some time or through a Button.

      There is not much to say:

      public class RateMeDialogTestActivity extends Activity
          * Called when the activity is first created.
         public void onCreate(Bundle savedInstanceState)
                                          "Google Inc.",//or null
                                          "Test",//or null
                                          1,//1 Days.
                                          3,//3 Launches.
         public void onShowDialog(View view)
                                          "Google Inc.",//or null
                                          -1,//Show it immediately.
                                          -1,//Show it immediately.


      If you want to create your own dialog, here is a short to-do list:

      1. Define the layout in an xml file, as any other layout.
      2. Extend DialogFragment.
      3. Override onCreateView() and in there inflate the layout. Eventually, retrieve the arguments with getArguments().
      4. To show the dialog, create a new instance, set the arguments through a Bundle, retrieve a FragmentTransaction, using a FragmentManager, and use it to actually show the dialog:
                RateMeDialog dialog = new RateMeDialog();
                Bundle params = new Bundle();
                params.putString(RATEMEDIALOG_PUBLISHER, publisherName);
                params.putString(RATEMEDIALOG_APPAPCKAGENAME, appPackageName);
                params.putString(RATEMEDIALOG_TITLE, title);
                //Show the dialog.
                FragmentTransaction ownerTransaction = ownerManager.beginTransaction();
                dialog.show(ownerTransaction, RATEMEDIALOG_TAG);

        Put everything in a static method, if you want to encapsulate the showing method in your subclass of DialogFragment.


About Luong

One Response to Take a rate, take a dialog!

  1. Alex says:

    I have been looking at this and want to use it but I don’t get how to add it? When I add a library its normally a jar file?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s