tutorial: how to make full and lite versions

After having read this article, I wanted to write down this knowledge for me and for other people who did not understand that article.

Therefore I first wrote a simple test app like the one in Donn’s article with two buttons which just display a toast message:

package net.example.bitowl.testapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class TestApp extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        Toast toast=Toast.makeText(v.getContext(), "Something is happening.",Toast.LENGTH_LONG);
        toast.show();
      }
    });
    final Button button_cool = (Button) findViewById(R.id.button2);
    button_cool.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        Toast toast=Toast.makeText(v.getContext(), "Something cool is happening.",Toast.LENGTH_LONG);
        toast.show();
      }
    });
  }
}

This is now the full version of my App.

On the project folder of “TestApp” do a rightclick. Then “Properties” -> “Android”. Check the box “Is Library”.

Create a new project which has the packagename of the full app with .lite behind it. Do not create an activity for it.

Rightclick on TestLite -> “Properties” -> “Android” -> “Libraries” -> “Add”

Select your “full” – project and click “OK”.

All the code of your “full”-project is now included in your “lite”-project.

You just need to tell the “lite”-project to also load the activity from the “full”-project.

Insert this lines into the AndroidManifest.xml:

        <activity android:name="net.example.bitowl.testapp.TestApp"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


Now both of your projects should result into the same app…

(note: If you link a lib into another project the assets-folder is not linked. So you need to copy your assets-folder also to the “lite”-project and keep it up to date.)

But you do not want all features of the full version to be in the lite one.

So create a method like this in your activity:

    public boolean isLite(){
    	return getPackageName().toLowerCase().contains("lite");
    }

Now if there is a feature that should not be in the lite-version, just add an if and maybe a message to purchase the full version:

        final Button button_cool = (Button) findViewById(R.id.button2);
        if(!isLite()){
	        button_cool.setOnClickListener(new View.OnClickListener() {
	            public void onClick(View v) {
	            	Toast toast=Toast.makeText(v.getContext(), "Something cool is happening.",Toast.LENGTH_LONG);
	            	toast.show();
	            }
	        });
        }else{
            button_cool.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                	//This is not allowed in the lite version
                	Toast toast=Toast.makeText(v.getContext(), "You need to purchase the full version to do this.",Toast.LENGTH_LONG);
                	toast.show();
                }
            });
        }

In the lite version the “do something cool”-feature is not avaiable anymore :)

I hope this tutorial was useful for you and not in too bad english.

You can download the project files here: TestAppCode.zip

If you know how to do things better, find some spelling mistakes or just want to say something about this, please write a comment.

bitowl

About these ads

Tags: , , ,

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: