Monday, August 8, 2011

How to display EULA ("End User License Agreement") in Android apps

This example shows a barebone program to illustrate how to incorporate displaying EULA to user in an Android App. User can only proceed with using the app if he or she accepts the EULA. Once accepted, EULA will not be shown next time.

This Eclipse screen shot below shows the structure of the directories and the required files. Please review this.



1. Download Eula.java file from http://code.google.com/p/apps-for-android/source/browse/trunk/DivideAndConquer/src/com/google/android/divideandconquer/Eula.java?r=93

2. Content of EULAExampleActivity.java file is give below in its entirety. This is just skeleton code intended to illustrate the displaying of EULA in your actual program. 


package com.EULAExample;

import com.EULAExample.Eula.OnEulaAgreedTo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class EULAExampleActivity extends Activity implements OnEulaAgreedTo
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        //display EULA - intended for one time display if user accepts it.
        if( Eula.show(this) == true ) //...Proceed UI creating and further only if user accepts EULA
        {
            this.onEulaAgreedTo();
        }
       
        //..Move setContentView to onEulaAgreedTo() function, see below
        //setContentView(R.layout.main);
       
        //..Nothing else goes here -- move all UIs, etc to onEulaAgreedTo() method
       
    } //End of onCreate

    @Override
    public void onEulaAgreedTo()
    {
        // TODO Auto-generated method stub
        //Log.d("EULAExample", "1. inside onEulaAgreedTo");
        setContentView(R.layout.main);
       
        //..move all you UIs, etc. hire -- do not keep anything in onCreate()
        //Log.d("EULAExample", "2. inside onEulaAgreedTo");
       
    } //end of onEulaAgreedTo method
   
     
} //End of outer class


3. Add these to the res\values\strings.xml file:

    <string name="eula_title">End-User License Agreement</string>
    <string name="eula_accept">Accept</string>
    <string name="eula_refuse">Refuse</string>
   

4. Google the web for a sample EULA file. Modify as needed. Prepare a EULA file (a text file, Notepad can be used to create and save it). Drag and drop it under assets folder while in Eclipse. Important: EULA file cannot have any extension -- file name is simply, say, EULA


That must be it. Let me know if any problem.

1 comment:

  1. Download Eula.java file from:
    Link is broken

    ReplyDelete

Please do not hesitate to leave your comments.