Code Monkey home page Code Monkey logo

eric-sofisoftwarelic.tilicensing's Introduction

TiLicensing

Appcelerator Titanium module for Android Google Play Licensing

About Google Play Licensing

When you publish an Android application to Google Play, there is no protection to prevent copying the APK to other unlicensed devices. If your app is published normally, it can easily be pirated. With Google Play's Licensing service, your application can query Google Play at run time to obtain the licensing status for the current user, then allow or disallow further use as appropriate. This provides some measure of protection against piracy. Google Play Licensing's implementation uses strong encryption to store licensing data.

For more information about Google Play Licensing, please see http://developer.android.com/google/play/licensing/index.html.

About this Licensing module

This module implements Google Play Licensing suitable for use in Appcelerator Titanium apps. This module implements the Google recommended ServerManagedPolicy, which allows access to the application while the device is offline by caching responses locally. Protecting your valuable apps has never been easier!

Installation

Unzip the archive and copy com.sofisoftwarellc.licensing-android-1.0.zip to the Titanium folder.

On Mac, the Titanium folder is is usually ~/Library/Application Support/Titanium.

On Windows, the path varies by OS version.

Full instructions are here.

Usage

To implement using the module, follow these steps:

Add the module to the Titanium build:

Add the module descriptor to the modules section in tiapp.xml:

<modules>
...
	<module platform="android" version="1.0">com.sofisoftwarellc.licensing</module>
...
</modules>

Add the following to the section in tiapp.xml:

Make sure you have a Google Play publisher account and create an application. Obtain the application's license key from the Services and APIs screen in the Google Play Developer Console.

API

To access this module from JavaScript, you use the require statement:

var license = require("com.sofisoftwarellc.licensechecker");

The license variable becomes a reference to the Module object, and will be used to invoke further API calls.

initialize

license.initialize({
	key: key,
	salt: salt
	deviceId: deviceId		// OPTIONAL
});

The initialize method sets up the licensing service with a predefined application key (obtained from Google Play), an application-specific salt value, and an optional device id.

The application key is generated by Google Play's publisher site when you set up the application. It is a very long string, so make sure to copy and paste it correctly.

The salt value is a 40 hex character string that helps to encrypt the application licensing data. You should randomly generate it, once per application.

The device id is a unique string identifier for each end-user device. It is used by Google Play to encrypt and decrypt data on the specific licensed device, to prevent copying internal licensing data between devices. If you do not provide it as a parameter in initialize, it will default to android.Settings.Secure.ANDROID_ID. If you want greater security, you may wish to create a hash including the device IMEI or other unique device-specific data.

doLicenseCheck

license.doLicenseCheck(); This initiates the license check. When the license check has completed, the event listener will be called.

Event listener

Results of the license check are delivered through an event "licenseCheckerEvent". Register an event listener to retrieve the result.

var licenseCheckerCallback = function(e) {
	if (e.response == "allow") {
		// e.reason should be license.LICENSED, the server returned back a valid license response
	} else if (e.response == "dontAllow") {
		var reason = e.reason;
		if (e.reason == license.NOT_LICENSED) {
			// NOT_LICENSED means that the server returned back a valid license response
			// that indicated that the user definitively is not licensed.
			// You should put up a dialog, possibly with a market link to allow purchase.
		} else if (e.reason == license.RETRY) {
			// RETRY means that the license response was unable to be determined ---
			// perhaps as a result of faulty networking.
			// It is your option how to handle this. You could permit the app to continue, or if you have stricter requirements, 
			// you could require a retry.
		}
	} else if (e.response == "error") {
		// An internal error
		Ti.Api.error("licenseCheckerEvent error=e.reason");
	}
};

license.addEventListener("licenseCheckerEvent", licenseCheckerCallback);

You may wish to unregister the event listener and nullify the license module once the callback has completed, to free resources.

Debugging and testing

To debug and test licensing in your application, you must to set up a runtime environment that includes the necessary Google Play service. This can be either an Android device (1.5 or higher) that includes the Google Play application, or an Android emulator configured with the Google APIs Add-on, API level 8 or higher. See http://developer.android.com/google/play/licensing/setting-up.html#runtime-setup for details.

In the Google Play publisher site for your application, there is a section where you can set test responses. You can simulate an unlicensed copy, a server error, and other types of problems. You should test your app with each of these settings (making sure to completely quit the app in between tests) to make sure it handles each of the cases correctly.

Notices

Copyright (C) 2012,2015 Sofi Software LLC

Usage of this module is subject to the terms of service for Google Play Licensing.

eric-sofisoftwarelic.tilicensing's People

Contributors

eric-sofisoftwarellc avatar

Watchers

James Cloos avatar Brenton House avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.