Android licensing simple example


SDK Version: 
M3

Android Market Licensing is a network-based service that lets an application on an Android-powered device query a trusted licensing server, to determine whether the application is licensed to the current device user. After receiving the server response, the application can then allow or disallow further use of the application as needed. In the service, the role of the licensing server is to provide the license status for the current user; the application itself is responsible for querying the server and conditionally granting access to the application.

You can find the licensing library and a cool sample application in your android-sdk folder after you download it with Android SDK and AVD manager. This tool located under Windows menu in Eclipse.

Copy the library and the sample projects into your workspace and create an Android project both of them.

After this step set your sample application as shown below.

Select the "Android" properties group and click Add, then choose the LVL library project (com_android_vending_licensing) and click OK.

To use Android licensing add this permission line into your AndroidManifest.xml file:

  1. <uses-permission android:name="com.android.vending.CHECK_LICENSE">

We are going to implement the default policy, this is the easiest way to licence your application.

In first lines of sample application set these lines:

  1.     private static final String BASE64_PUBLIC_KEY = "REPLACE THIS WITH YOUR PUBLIC KEY";
  2.  
  3.     // Generate your own 20 random bytes, and put them here.
  4.     private static final byte[] SALT = new byte[] {
  5.         -46, 65, 30, -128, -103, -57, 74, -64, 51, 88, -95, -45, 77, -117, -36, -113, -11, 32, -64,
  6.         89
  7.     };

Bottom of this file use the implemented methods as you want. For example in MyLicenseCheckerCallback class there is the dontAllow() method. This method runs when market checking returns false. In my last project I blocked the main menu elements in this method.