When you go through the in app billing documentation, you kinda realize that it can take substantial amount of time to understand this complex piece of technology. Most developers feel the need for a working HelloWorld, and then later play around with the builds.
I have uploaded 2 projects
The android sample project. You can download this project, and immediately run the sample. This will help you quickly debug/trace thru and figure out how the in app billing works.
A cleaned up project to help you integrate your app quickly. This can help like a library. Just integrate make your “purchase requests” on your “checkout” button action.
Mind you : I have not incorporated the security recommendations. Read android in app billing documentation. Until then you are on your own risk.
For 1
- Download “http://www.4shared.com/file/f5wH3qke/InAppBilling1.html”
- Create a new gmail account for all correspondence (Why, I will explain below)
- Pay that 25$ and purchase a “Market Place” account.
- Import the project to your eclipse environment
- Create a signed application apk, File-Export-Select Your Project-Create OR Use keystore, it should be valid for 25 years from today.
- Upload the signed apk to the market place as a “Draft Application”, DO NOT PUBLISH it.
- For the uploaded apk, you need to add “In App Products”. You will find this link on the home page for your uploaded apk.
- In Security.java dont forget to add your “public key” from your market place account “edit profile” page.
- On the “In App Product List”, you need to add the following products one by one
- The text below should used as “In app Product id”
- sword_001 as Managed
- potions_001 as Unmanaged
- Title and Description dont matter (for testing purpose). Add what you need here.
- Cost add 1$ (minimum)
- Click auto fill
- Save
Publish the in app project (dont get confused here, you only need to publish the in app product, NOT the APP)
- In the test account, add your personal gmail id here. Now, this gmail account needs to be configured as your first gmail account on your phone.
- Yes, this WONT work on your emulator
- Now the sample app should work.
For 2
Download “http://www.4shared.com/file/h8YnJyf_/InAppBillingIntegration.html”
To integrate, in your calling activity initialize the checkout code
Handler handler = new Handler() ;
CheckoutPurchaseObserver checkout = new CheckoutPurchaseObserver(this, handler);
To send the checkout request for your product
checkout.sendCheckoutRequest(purchaseUri.toString(),null);
Important Note :
- This purchaseUri is the “In-app Product ID” of your resource on the “market.android.com/publish-->Create New In-App Product” options. This string should be set as the “in app product” id.
- That’s why the “id” is most important. The “In-App Product ID” is how you refer to that particular product.
- Also, in Security.java dont forget to add your “public key” from your market place account “edit profile” page.**
Debugging Notes
- LogCat will show all errors as InAppBilling tag
- This project creates a shared_preferences named “inappbilling” And debug is set to true
- The androidmanifest.xml may not be needed since this project does not
have a home screen.
Why do we need to create a new gmail account ?
Simple. The account you purchase your market place account for, cant be used for “testing” your in app billing. Since you cannot purchase products for yourself. And your primary account on your device should be set as a “test account” on the market place account. Chicken-Egg issue here. Hope its clear.
An interesting blog I came by “http://crazyviraj.blogspot.com/2011/06/some-notes-on-implementing-in-app.html“ (not mine).