Creating an Android EULA Activity
Tags: android
Published: 2020-03-30 16:39:28

---
title: Creating an Android EULA Activity
published: true
date: 2020-03-29 19:05:00 UTC
tags: android
canonical_url: https://www.stephanmiller.com/a-generic-android-eula-activity/
---

## What is a EULA?

It stands for end-user license agreement, and it is a legal contract between the developer of an application and the user of that application. Most developers “shrink-wrap” their application with the EULA agreement, not allowing users to access any part of the application without first clicking “Agree”. That is the type of EULA we will be creating.

## Why is a EULA necessary for your Android app?

- A EULA can give you the right to terminate the license or stop supporting the application without fear of legal repercussion.
- A EULA allows you to provide your app on an “As Is” basis and disclaim warranties.
- A EULA will allow you to limit your liability.
- A EULA can restrict undesirable usage of your application such as spamming, hacking or reverse engineering.
- A EULA will license the app to your user without selling them full ownership of the app.

![](https://www.stephanmiller.com/images/2020/03/2020/android-eula.png)

## Create a reuseable EULA activity for your Android application.

Any application you plan on selling or giving away should have a EULA. I recently had to come up with one for an Android application. It had to be used by a few of the activities in the application because it had a bottom navigation menu and multiple entry points.

The EULA activity is below. It is using SharedPreferences to store the eulaAccepted variable. In real life, you would probably have a whole user object that you cache with SharedPreferences but then save to a remote API once the user accepts the EULA.

It would seem natural to display HTML in Android in a WebView and that was the other option. You just have to load the file path to the resource in WebView. With this method, just add an HTML file to the res/raw/ folder and access it by the resource id. This resource id is passed in with the intent when the activity is started.

Confirming the EULA sets the eulaAccepted variable. Canceling the EULA does nothing other than show a snackbar that tells you that you have to accept the EULA to continue.

<noscript><pre>400: Invalid request
</pre></noscript><script src="https://gist.github.com/87066ee18a0435e90c9cbca6db03a741.js?file=EulaActivity.kt"> </script>
## The Android EULA layout

Here is the layout for the EULA:

<noscript><pre>400: Invalid request
</pre></noscript><script src="https://gist.github.com/87066ee18a0435e90c9cbca6db03a741.js?file=activity_eula.xml"> </script>
## Using the EULA Activity in other activities.

To “shrink wrap” your Android app with your EULA, just run the checkEula method below right after you call setContentView in onCreate on any Activity in your app users can enter from.

In the checkEula method, we see if the user has accepted the EULA by checking SharedPreferences and if they haven’t, we set the eula value in intent and start EulaActivity.

<noscript><pre>400: Invalid request
</pre></noscript><script src="https://gist.github.com/87066ee18a0435e90c9cbca6db03a741.js?file=MainActivity.kt"> </script>
## Raw EULA html resource file.

This is just a basic EULA that I copied an online EULA generator for this example. You can generate a EULA for your app at one of these sites for free:

- [https://www.eulatemplate.com/eula-generator](https://www.eulatemplate.com/eula-generator)
- [https://www.termsfeed.com/eula-generator/](https://www.termsfeed.com/eula-generator/)
- [https://www.privacypolicies.com/eula-generator/](https://www.privacypolicies.com/eula-generator/)
<noscript><pre>400: Invalid request
</pre></noscript><script src="https://gist.github.com/87066ee18a0435e90c9cbca6db03a741.js?file=eula.html"> </script>

You can access the complete Github gist [here](https://gist.github.com/eristoddle/87066ee18a0435e90c9cbca6db03a741). And you can find the code used in an example project [here](https://github.com/eristoddle/Android-Experiments).