Showing EULA in Android App


Some applications require EULA (End User License Agreement) to be shown based on application’s features and data usage. This post we will see how easy it is to implement in android apps.

Requirements:

  • User installs app
  • User opens app
  • User should be presented with a popup dialog/screen with EULA details
  • User either accepts or cancels
    • Accept : continue app use
    • Cancel : close the app
  • User uses app, closes it
  • User re-opens app for subsequent uses. EULA should not be displayed again
  • An update of app is released
  • User upgrades the app
  • User opens app and updated EULA should be shown again

Code:

Add following string elements into your res/values/strings.xml file. Change the text as per you liking, and do replace APP_NAME with your app’s name !

Note: While discussing this article with a reader, he suggested that EULA text be placed in a file inside assets folder and then read from there. However, I strongly disagree with this method, because EULA text placed in strings.xml file inside values folder makes it easy to internationalize it. Place the strings.xml file inside folder of another locale (ex values-es) and change the text accordingly.

<string name="accept">Accept</string>
<string name="eula_string">COPYRIGHTS:

\nCopyright 2013 APP_NAME. All Rights Reserved.

\n\nThis software may not, in whole or in any part, be copied, reproduced, transmitted, translated (into any
language, natural or computer), stored in a retrieval system, reduced to any electronic medium or machine readable
format, or by any other form or means without prior consent, in writing, from APP_NAME.

\n\nYou are granted a limited license to use this software. The software may be used or copied only in accordance
with the terms of that license, which is described in the following paragraphs.

\n\nTRADEMARKS:
\n\n[Software logos, icons, etc that are Trademarked]

\n\nLICENSE:
\n\n\"THE SOFTWARE\" shall be taken to mean the software contained in this app and any subsequent versions
or upgrades received as a result of having purchased this app. \"BUYER\" shall be taken as the original
purchaser of the software.

\n\nBuyer has the non-exclusive right to the use of software only on a single device. Buyer may not electronically
transfer the program from one device to another over any type of network. Buyer may not distribute copies
of the software or the accompanying documentation to others either for a fee or without charge. Buyer may not modify
or translate the program or documentation. User may not disassemble the program or allow it to be disassembled
into its constituent source code. Buyer\'s use of the software indicates his/her acceptance of these terms
and conditions. If buyer does not agree to these conditions, return the distribution media, documentation, and
associated materials to the vendor from whom the software was purchased, and/or uninstall the software from the device,
and erase the software from any and all storage devices upon which it may have been installed.

\n\nThis license agreement shall be governed by the laws of The United States of America, Massachusetts and
shall inure to the benefit of APP_NAME or its assigns.

\n\nDISCLAIMER / LIMITATION OF LIABILITY:
\n\nBuyer acknowledges that the software may not be free from defects and may not satisfy all of buyer\'s
needs. APP_NAME warrants all media on which the software is distributed for 60 days to be free from defects
in normal use. The software and any accompanying written materials are licensed \"AS IS\". Buyer\'s exclusive
remedy during the warranty period (if any) shall consist of replacement of distribution media if determined to be
faulty. In no event will APP_NAME be liable for direct, indirect, incidental or consequential damage or
damages resulting from loss of use, or loss of anticipated profits resulting from any defect in the software,
even if it has been advised of the possibility of such damage. Some laws do not allow exclusion or limitation
of implied warranties or liabilities for incidental or consequential damages, so the above limitations or
exclusion may not apply.

\n\nSPECIFIC RESTRICTIONS:
\n\nIn accordance with the COMPUTER SOFTWARE RENTAL ACT OF 1990, this software may not be rented, lent or leased.
\n\nThe software and accompanying documentation may not be provided by a \"Backup Service\" or any other vendor
which does not provide an original package as composed of APP_NAME, including but not limited to all original
distribution media, documentation, registration cards, and insertions.</string>

In your Activity, show EULA like this:


// Show EULA

new AppEULA(this).show();

And here is the code for AppEULA class, with self-explanatory comments:

/**
 * This file provides simple End User License Agreement
 * It shows a simple dialog with the license text, and two buttons.
 * If user clicks on 'cancel' button, app closes and user will not be granted access to app.
 * If user clicks on 'accept' button, app access is allowed and this choice is saved in preferences
 * so next time this will not show, until next upgrade.
 */
package com.app.db;

import com.app.sample.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.preference.PreferenceManager;

public class AppEULA {
	private String EULA_PREFIX = &quot;appeula&quot;;
	private Activity mContext;

	public AppEULA(Activity context) {
		mContext = context;
	}

	private PackageInfo getPackageInfo() {
		PackageInfo info = null;
		try {
			info = mContext.getPackageManager().getPackageInfo(
					mContext.getPackageName(), PackageManager.GET_ACTIVITIES);
		} catch (PackageManager.NameNotFoundException e) {
			e.printStackTrace();
		}
		return info;
	}

	public void show() {
		PackageInfo versionInfo = getPackageInfo();

		// The eulaKey changes every time you increment the version number in
		// the AndroidManifest.xml
		final String eulaKey = EULA_PREFIX + versionInfo.versionCode;
		final SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(mContext);

		boolean bAlreadyAccepted = prefs.getBoolean(eulaKey, false);
		if (bAlreadyAccepted == false) {

			// EULA title
			String title = mContext.getString(R.string.app_name) + &quot; v&quot;
					+ versionInfo.versionName;

			// EULA text
			String message = mContext.getString(R.string.eula_string);

			// Disable orientation changes, to prevent parent activity
			// reinitialization
			mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

			AlertDialog.Builder builder = new AlertDialog.Builder(mContext)
					.setTitle(title)
					.setMessage(message)
                    .setCancelable(false)
					.setPositiveButton(R.string.accept,
							new Dialog.OnClickListener() {

								@Override
								public void onClick(
										DialogInterface dialogInterface, int i) {
									// Mark this version as read.
									SharedPreferences.Editor editor = prefs
											.edit();
									editor.putBoolean(eulaKey, true);
									editor.commit();

									// Close dialog
									dialogInterface.dismiss();

									// Enable orientation changes based on
									// device's sensor
									mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
								}
							})
					.setNegativeButton(android.R.string.cancel,
							new Dialog.OnClickListener() {

								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									// Close the activity as they have declined
									// the EULA
									mContext.finish();
									mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
								}

							});
			builder.create().show();
		}
	}
}

Final Result:

EULA

EULA Popup Dialog

If you don’t have a company for publishing and releasing apps, you can use the EULA sample from here:
Sample EULA wihtout a company

Happy using EULA and go publishing!

Additional Notes:

EULA is now considered an “Anti-pattern” as per “Android Design Patterns: Interaction Design Solutions for Developers” (Wiley, 2013) by Greg Nudelman, and should be presented to user in such a way that it doesn’t stop and force them to read it. If user wants, link should be handy and easy to find in the application and as small as possible.

Blog post: End User License Agreement (EULA) presentation

Advertisements
About

An all round Software Engineer with 8 years of software development experience looking to work on exciting projects with exciting clients. Full of energy, experience, hard work and enthusiasm, I need a new challenge and want to work in the heart of the web software industry.

Tagged with: , ,
Posted in Android, Code
13 comments on “Showing EULA in Android App
  1. sushil says:

    many thanks ..

  2. Thanks, this is great 🙂

  3. ramana says:

    thanks jayesh 🙂

  4. Hemanth says:

    I guess

    // EULA text
    String message = mContext.getString(R.string.eula_string);

    this must come instead of eula

  5. RikenMon says:

    Thanks very much, just what I needed. I added:

    .setCancelable(false)

    at the alertdialog builder so one can not escape by pressing back

  6. Pistey says:

    Thanks for this easy reference.

  7. prasad says:

    is there any method to pass value to main class if i clicked on accept button???

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Visit My Website
Posts
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 136 other followers

%d bloggers like this: