—–Start of Advertisement——-
BUILD CAR POOL SOLUTIONS ON ANY DEVICE TO RUN ANYWHERE (www.mcruiseon.com). Introducing mCruiseOn, the java library /json api’s that you can use to build a car pool solution. Be the next avego.com, carpooling.com, zimride.com. mCruiseOn is your one stop API on EC2.
——End of Advertisement——-
The android in app billing documentation and implementation is a night mare. It takes more time then it should. It can take time to understand this complex piece of technology. So for those smart people around, who have less time to go through all that documentation, here goes.
I have uploaded 2 projects
- A sample project, that you just download and play with the in app billing features. Play with it, debug it and understand/figure it out.
- A cleaned up project to help you integrate your app quickly. As of now android sdk is a bit screwed up to allow this project to be a library. So I’ll just guide you to integrate this in your application.
Mind you : this is a simple implementation. I have not incorporated the advanced security recommendations in the projects below. Read android in app billing documentation, to get advanced security features. Until then you are on your own risk.
Sample Project Instructions
- 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, may be more, since other countries too have a minimum)
- Click auto fill
- 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.
To Enable InApp in your Application
- Download “http://www.4shared.com/file/h8YnJyf_/InAppBillingIntegration.html”
- Copy all the packages to your project
- Copy the layout files, string values and color values.
- Copy the contents of <application> from the manifest to your manifest.
- Provide correct package names to your class file references in the manifest file
- Add the BILLING and INTERNET permissions
- You may want to rename main.xml to purchase_main.xml, and also change the setContentView in Dungeons.java
- Clean it up and get it to compile.
- 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
Configure your Play Developer account for in app
- First, you need a merchant account
- Very important point, test account should have the email address, that your device is using as the primary account for gmail.
- Only the signed version of the application will work, so dont install from your Run Configurations in Eclipse
- 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.
- 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.
- Now for the last part of this blog. 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.
If you cant get any of this to work, or find out that I have missed out on some steps, please comment and let me know.
An interesting blog I came by “http://crazyviraj.blogspot.com/2011/06/some-notes-on-implementing-in-app.html“
A very interesting Question from Stackoverflow. here
Edit : manifest file permissions (thanks to Jeff Ortiga)