This is a library (released in form of an Android Library Project) to simplify the integration of in-app billing service offered by google in your applications
It's is based on reference application, the Dungeons example. Using this library you will not have to learn how to the service works, simply use it in few steps.
Step1 : Create an Application class
Firt of all you must create an applicatin class (or reuse it if you havealready one in your project).
The application class is necessary because in this class (started before other classes) you will register your developer public key and try to restore previous market transaction (in case your application is not installed for the first time and the user have already purchased items last time)
Here an axample of what this class must do (at least).
Where you must specify your developer public key taken it from the android developer console.
After you have created your class you must register it in androidManifest.xml file using the attribute android:name of tag application. See step3 for a complete example of file.
Step 2 : Create your custom billing activity
In this step you must create an activity that will be used to sell your products. This step is simplify using the base class provided in library. Using the base class you will have to implements only your custom behaviour (if you have one) and define the product list to sell.
The extended class must implements three method:
In this method you can decide if you want to continue the purchase flow or you want to stop the process.
Return true if you want to continue, false otherwise.
In this methid you have the opportunity to do something after
the state of yours productId has changed (purchased or refused).
This step is not mandatory, but if you want to integrate with your server after purchase, this is place where you can do it.
this is the more important method of class. It define the productId list of items that you want to sell.
Each BillingCatalogEntry is an instance of productId. The activity will show a Spinner with all items defined and for each item will show a description in a webView (the description can be simple text or html text).
The costructor of BillingCatalogEntry take this parameter:
- productId : The productId of item. This must be the same of one defined on developer console. If this value is null, the item will be shown but will not be purchable, this case is used if you want to give a global description of your market items.
- Title: This is the title of your productId. It will be used in spinner
- Descrition: String used for description. This value can have more meanings:
- Text plain : The text will be used as is.
- String that starts with 'http://': The URL will be shown in a webView. This can be used if you want to give a more complex description of your products
- String that ands with '.html': This will be include a local resourse (taken form res/raw folder).
Step 3 : Register all in your androidManifest.xmlIn last step you must modify your androidManifest.xml in order to add you billing activity, set the right permission and register the service and broadcast receiver provided by library to interact with the in-app billing service.
Here a complete example of file: