Android Microtransaction Library (In App Billing)

Download

Use the following links to download this project:

Download Microtransaction Source Code Beta 1 – This is a beta release of the project.  It needs more testing and refinement to be production ready.

Introduction

The purpose of this project is to help Android developers implement microtransactions (in app billing) in their Android projects.  Using the Google provided examples (here http://developer.android.com/guide/market/billing/index.html), we have created a set of abstractions that make it much easier to interact with the billing system.  Developers no longer need to worry about all the internal workings of the billing system and all the complex messaging.

NOTE: This project is currently in beta.  It will improve over time.  If you have suggestions, bug fixes, or want to contribute code, please email disgruntledrats@gmail.com.

Design

Here is the class diagram for the Microtransaction library:

 

 

Here is a short description of each of the classes in this library:

  • Purchase – A set of items and their quantities that have been purchased from the store
  • Item – Something purchased
    • Disposable Item – Google calls these items “unmanaged”.  They are not restored when the application is reinstalled.
    • Permanent Item – Google calls these items “managed”.  They are restored when the application is reinstalled.
  • Store – An abstraction that greatly simplifies the purchasing of items.  It hides all the complexities of the Google in-app billing APIs
  • Safe – This is where items are automatically stored after they are purchased.  Developers just want items to show up and not worry about the complex handshakes involved in billing.
  • Billing Activity – This is the base class each application needs to extend to use the library.
  • Android Market Account – An abstraction that hides your Google publisher ID.

 

Running the Example

Prerequisites
Here is a list of prerequisites before this project can be used.

1. Download and install the Android SDK.

2. Plug your Android phone into your computer.

3. Make sure USB debugging is enabled on your phone.

4. Run ADB as root on your linux box. Here is an example of how to do that
in Ubuntu:
$ sudo -E ./bin/android-sdk-linux_x86/platform-tools/adb start-server

Running on Your Phone

Here are the steps necessary to run this project on your phone.

1. Change the “sdk.dir” variable in the local.properties file. It needs to
be set to the path of the Android SDK you downloaded.

2. Change the “jdk.dir” variable in the local.properties file. It needs to
be set to the path of your Java Development Kit directory.

3. Change the “target” variable in the “default.properties” file. It needs
to be the name of your Android target. Look in your
“android-sdk-linux_x86/platforms” directory for examples targets you have
installed.

4. Create a new package for your Activity in the “src/main” directory. The
reason you want to do this is because I think the package names are bound
to your Android Market account. So, “com.disgruntledrats” is already being
used. I recommend you chose something else. 🙂

5. Create a new class that extends “BillingActivity”. Look at the
“ApplicationActivity” class for an example of what’s needed in this class.

6. Log in to your Android Market publisher account.

7. On the upper left part of the page, under your name, click Edit Profile.

8. On the Edit Profile page, scroll down to the Licensing & In-app Billing panel.

9. Copy your public key and place it in the return of your anonymous
“AndroidMarketAccount” class. The reason for this obfuscation is to eliminate
the need for holding this key in program memory for long periods of time.

10. Edit the “AndroidManifest.xml” file and change “activity android:name=”
to match the new Activity class you created in the previous steps.

11. Choose a new key for your keystore. Enter the value for “keystore.password”
in “build.properties” under the item .

12. Create a new keystore by running the following command. Use the key you
chose in the previous step. This will create a keystore file in the root
directory of the project.
$ ant create-key

13. Run the following command to create an Android package. When it asks for
your keystore password, enter the value for “keystore.password” you put in the
“build.properties” file.
$ package-android

14. Upload the generated package to the Android Market. It’s located in the
following location:
target/android/microtransaction.apk

15. Install the sample package on your phone. Enter the keystore password
you chose in the previous steps when it asks for it.
$ ant install

16. On the “Edit Profile” page of you Android Market account, add the test
account email address used by your phone. This will allow you to execute fake
transactions.

17. Run the “Microtransaction Example” program on your phone.

18. Make sure you choose the FAKE account when it asks for your billing
information. Otherwise, you could see a charge on your phone.

Using the Library

1. Run the following command to create a JAR file you can use in another
project.

ant jar

 
2. Make your default Android Activity extend “BillingActivity”.
 
3. Follow the code in the example “ApplicationActivity” class.
 

1 thought on “Android Microtransaction Library (In App Billing)”

Comments are closed.