Skip to content
marchbold edited this page Aug 14, 2020 · 1 revision

Licensing

Google Play Licensing is a network-based service that lets an application query a trusted Google Play licensing server to determine whether the application is licensed to the current device user. The licensing service is based on the capability of the Google Play licensing server to determine whether a given user is licensed to use a given application. Google Play considers a user to be licensed if the user is a recorded purchaser of the application.

The com.distriqt.playservices.Licensing extension implements the client side Licensing Verification Library and exposes the functionality to AIR.

More information on Play Licensing can be found here.

Add the Extension

First step is always to add the extension to your development environment. To do this use the tutorial located here.

The com.distriqt.playservices.Licensing is independent of the other Google Play Services extensions, however you do need to add the Core ANE as a dependency to your application.

Core

The Core ANE is required by this ANE. You must include and package this extension in your application.

The Core ANE doesn't provide any functionality in itself but provides support libraries and frameworks used by our extensions. It also includes some centralised code for some common actions that can cause issues if they are implemented in each individual extension.

You can access this extension here: https://github.com/distriqt/ANE-Core.

Extension IDs

The following should be added to your extensions node in your application descriptor to identify all the required ANEs in your application:

<extensionID>com.distriqt.Core</extensionID>
<extensionID>com.distriqt.playservices.Licensing</extensionID>

Android Manifest Additions

You must add the com.android.vending.CHECK_LICENSE permission to your manifest additions:

<manifest android:installLocation="auto">
	<uses-sdk android:minSdkVersion="14" />
	<uses-permission android:name="com.android.vending.CHECK_LICENSE" />

</manifest>

Usage

Imports

You will need to add the following imports:

import com.distriqt.extension.playservices.licensing.PlayLicensing;
import com.distriqt.extension.playservices.licensing.events.PlayLicensingEvent;

Setup

You will need to pass your Base64 public license key and a salt value to the extension by calling the setup() function:

var BASE64_PUBLIC_KEY: String = "BASE64_PUBLIC_KEY";
var SALT:Vector.<int> = Vector.<int>( [ 1, 43, -12, -1, 54, 98, -100, -12, 43, 2, -8, -4, 9, 5, -106, -108, -33, 45, -1, 84 ]);
		
PlayLicensing.service.setup( BASE64_PUBLIC_KEY, SALT );

Check License

To check whether the current user is licensed to use your application call the checkAccess() method:

PlayLicensing.service.checkAccess();

Handle Event

The response from the check license will be in the form of one of three potential events:

  • PlayLicensingEvent.ALLOW: Allow use. App should proceed as normal.
  • PlayLicensingEvent.DONT_ALLOW: Don't allow use. App should inform user and take appropriate action.
  • PlayLicensingEvent.ERROR: Error in application code or the state of the application (eg in debug mode)

Each of these events comes with some additional information. For the PlayLicensingEvent.ALLOW and PlayLicensingEvent.DONT_ALLOW, the reason property on the event will contain the reason the event occurred as one of the values defined in the Policy class. For the PlayLicensingEvent.ERROR the errorCode will be one of the values defined in the ErrorCodes class.

PlayLicensing.service.addEventListener( PlayLicensingEvent.ALLOW, checkAccessResponseHandler );
PlayLicensing.service.addEventListener( PlayLicensingEvent.DONT_ALLOW, checkAccessResponseHandler );
PlayLicensing.service.addEventListener( PlayLicensingEvent.ERROR, checkAccessResponseHandler );
		
function checkAccessResponseHandler( event:PlayLicensingEvent ):void
{
    trace( "checkAccessResponseHandler(): " + event.type );
    trace( "   reason:    " + event.reason );
    trace( "   errorCode: " + event.errorCode );
}

Example

var BASE64_PUBLIC_KEY: String = "BASE64_PUBLIC_KEY";
var SALT:Vector.<int> = Vector.<int>( [ 1, 43, -12, -1, 54, 98, -100, -12, 43, 2, -8, -4, 9, 5, -106, -108, -33, 45, -1, 84 ]);
		
PlayLicensing.service.setup( BASE64_PUBLIC_KEY, SALT );

PlayLicensing.service.addEventListener( PlayLicensingEvent.ALLOW, checkAccessResponseHandler );
PlayLicensing.service.addEventListener( PlayLicensingEvent.DONT_ALLOW, checkAccessResponseHandler );
PlayLicensing.service.addEventListener( PlayLicensingEvent.ERROR, checkAccessResponseHandler );


PlayLicensing.service.checkAccess();


function checkAccessResponseHandler( event:PlayLicensingEvent ):void
{
    trace( "checkAccessResponseHandler(): " + event.type );
    trace( "   reason:    " + event.reason );
    trace( "   errorCode: " + event.errorCode );
}