Quantcast
Channel: bees4honey blog » EULA
Viewing all articles
Browse latest Browse all 2

Adding EULA to Android app

$
0
0

EULA ( End User License Agreement ) is not required to publish your Android app on Market, but it’s a good practice to protect yourself by concluding an agreement with your user. So in this post I will describe simple and quick method of implementing EULA in Android application.

Our EULA implementation is based on class available here. We are using Eclipse 3.3 with ADT plugin installed. So we need to do the following steps to add EULA to Android application:

  1. Download or copy Eula class source code from here.
  2. Add Eula.java file containing Eula class source code to Android application.
  3. Add necessary string resources.
  4. Add text file, containing EULA text into ‘asset’ application folder.
  5. Call Eula.show method in Create event handler of the main Activity.

Now let us study each step in detail. The first step doesn’t demand any explanations, that is why let us go to the second one.

EULA Class Content

Method Description
static boolean show(final Activity activity) Is responsible for a display of “dialogue window” with EULA text and processing of user actions
private static void accept(SharedPreferences preferences) Records a value, which confirms that the user has accepted a license agreement, into application state
private static void refuse(Activity activity) Closes the main Activity
private static CharSequence readEula(Activity activity) Reads EULA text from the file
private static void closeStream(Closeable stream) Closes a thread passed as a parameter, in particular a thread of reading EULA text

Adding EULA Class To Your Project

In order to add EULA class source code into application it is necessary to copy Eula.java file into the folder with source codes of your application (e.g. for BrainTwister the path will be as follows: BrainTwister\src\AndroidDevStudio\Games\BrainTwister). It is also possible to drag Eula.java file in Eclipse into BrainTwister\src\AndroidDevStudio.Games.BrainTwister folder. In any case the result should look as the one presented on the following image:

EULA class in your Android application

EULA class in your Android application

It is also possible to add the class using Eclipse tool “New Java Class” in the following way: add an empty class, then copy Eula class code copied from the site into the created file. In both cases, it may be needed to add a link to the package of the application into which EULA is added.

Adding String Resources

Now it is necessary to add missing resources into the application, in particular, the following string resources:

  1. eula_title it isdialogue windowheader text, which allows a user to get familiarized with EULA text and accept or refuse from it.
  2. “eula_accept” – it is a text, which is displayed on the button implementing “Accept” action.
  3. “eula_refuse” it is a text, which is displayed on the button implementing “Refuse” action.

String resources are added to res\values\strings.xml file and possibly could be as follows:

  1. <string name=“eula_title”>License</string>
  2. <string name=“eula_accept”>Accept</string>
  3. <string name=“eula_refuse”>Refuse</string>

Adding EULA File To Project

Now we should add file with EULA text to your project. Please note that file should not have any extension and must be placed into “assets” folder. First create *.txt file, add it to project and then remove extension. It should look like that:

EULA File In Your Project

EULA File In Your Project

Call Eula.show() Method

And at the last step you should call show() method from Eula class in the very beginning of Create events handler in the main Activity. You should also pass Activity which should be closed if user refuses EULA. Code will look like this:

@Override
public void onCreate(Bundle savedInstanceState)
{
Eula.show(this);

}

And that’s it – we are ready to see the result! Start your application and you will see something like that:

EULA in Android App Example

EULA in Android App Example

If user clicks “Refuse” button then application will be closed. If user accepts EULA, then it will never be shown again.

Testing EULA

Every application must be tested. So we should test EULA few times. We can write indicator to application state which says that user did not accepted EULA yet. The following code should be inserted at the beggining of show() method in Eula class:
preferences.edit().putBoolean(PREFERENCE_EULA_ACCEPTED, false).commit();

Just do not forget to remove it after testing ;)

Related posts:

  1. How To Prepare Android Application For Market
  2. Pseudo 3D Graphics for Android Game. Isometric basics.
  3. How to install non-Market app on G1?

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images