views:

98

answers:

2

I'm about ready to market my first Android App (from a US Google Checkout/Merchant account with US bank account etc.), and I would like to have the user at least agree to some kind of simple liability disclaimer before he/she can install the app.

To your knowledge, is it possible, and if so, what would be the best way to do this?

Your help and tips are greatly appreciated.

+3  A: 

When you say "before he/she can install the app" I guess you mean that in the same screen that allows users to install apps you want to put a disclaimer. Well, I think it's not possible. In fact, an application can be installed in different ways (from third party apps, or by using abd install on a rooted handset).

So, my suggestion is to place that disclaimer in the main activity. You can save the user decision somewhere (the easiest way is a preference). That way, you can check whether the user has accepted the disclaimer. Of course, if the user does not accept, you just don't let him/her use your app.

Simple example

public class MainActivity extends Activity {
    public static final String PREFS_NAME = "user_conditions";

    @Override
    protected void onCreate(Bundle state){         
       super.onCreate(state);
       // bla bla bla

       // Check whether the user has already accepted
       SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
       boolean accepted = settings.getBoolean("accepted", false);
       if( accepted ){
           // do what ever you want... for instance:
           startActivity(new Intent(this, RealApp.class));
       }else{
           // show disclaimer....
           // for example, you can show a dialog box... and,
           // if the user accept, you can execute something like this:

           // We need an Editor object to make preference changes.
           // All objects are from android.context.Context
           SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
           SharedPreferences.Editor editor = settings.edit();
           editor.putBoolean("accepted", true);
               // Commit the edits!
           editor.commit();
       }
    }
}
Cristian
What an awesome response, Cristian. Thank you so much.
Chris Dickinson
+1  A: 

Here's how I implemented the Dialog according to Cristian's example:

In the activity class, I created this method:

    protected Dialog onCreateDialog(int id){
    // show disclaimer....
    // for example, you can show a dialog box... 
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("LEGAL DISCLAIMER: ... ")
           .setCancelable(false)
           .setPositiveButton("Agree", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   // and, if the user accept, you can execute something like this:
                   // We need an Editor object to make preference changes.
                   // All objects are from android.context.Context
                   SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                   SharedPreferences.Editor editor = settings.edit();
                   editor.putBoolean("accepted", true);
                   // Commit the edits!
                   editor.commit();                    
               }
           })
           .setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    nm.cancel(R.notification.running); // cancel the NotificationManager (icon)
                    System.exit(0);
               }
           });
    AlertDialog alert = builder.create();
    return alert;
}

At the beginning of the onCreate() method, I added these lines:

    // Check whether the user has already accepted
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    boolean accepted = settings.getBoolean("accepted", false);
    if( accepted ){
        // do what ever you want... for instance:
    }else{
        showDialog(0);
    }

Cheers, Chris

Chris Dickinson