Integrate In App billing, just 3 lines of code in your app

40

Self Advertisement 🙂

Self Advertisement
—–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

  1. 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.
  2. 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
  • 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.

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

checkout.sendCheckoutRequest(purchaseUri.toString(),null);

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.

Note :

  • 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)

zXing 1.7 for Android, on eclipse

7

Self Advertisement
—–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 zxing guys have made it easier to create a android project with 1.7. Its not as painful as it used to be. This is a quick blog for anyone who would like to create a zxing project for android quickly.

– Checkout the zxing sources from zxing.org
– Create a Android project on your eclipse
– Delete main.xml
– Right click on “src” directory and hit import. Browse to the following directories in the order mentioned. As you add them for import one by one, ensure that you have the src directory in the edit field of the import wizard. And that you select only the “com” directory on the left directory tree. Do not select src.
* core
* android-integration
* android
– Ensure that your android sdk version is 9, anything lesser and androidmanifest.xml will cry.
– Strings.xml in one of the languages will crib, just put a / before the ‘ character

A android project for zxing 1.7 (June 20 checkout).
http://www.4shared.com/file/bFx8Y5Ys/zXingJune2010.html

Edited
One more interesting blog to help you out
http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/

Self Advertisement 🙂
BUILD CAR POOL SOLUTIONS ON ANY DEVICE TO RUN ANYWHERE (www.mcruiseon.com). Introducing mCruiseOn, the java library 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.

Super Fast Ubuntu 11.04

0

I have a AMD laptop, not to mention that upgrading screwed bootup, I had to do a safe mode and uninstall nvidia drivers and install ati drivers. Finally got it up :), and was hit by slow, really slow ui. Researched a bit and found the following steps to install 2d, now works like a charm, SUPER FAST. This is the real ubuntu man..

sudo add-apt-repository ppa:unity-2d-team/unity-2d-daily
sudo apt-get update
sudo apt-get install unity-2d
logout
select unity-2d as your desktop

Enjoy

SecurityException Binder invocation to an incorrect interface (Inapp Billing)

3

Self Advertisement
—–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——-

I got this annoying exception when I tried to run the “In app billing” sample app. I followed all the required steps but kept getting this exception at load time.

I did the following
1) Setup a Market account
2) Renamed the package to not have “android” or “example”
3) Added the public key from the market profile to Security.java
4) Built/Signed the app
5) Added “inapp products” to the market place
6) Uploaded as draft app
7) Uninstalled the sample on the device
8) Installed it on the device
9) Ensured that market place was > 2.3.5
10) Setup a test account. And this test account should not be the account registered for this developer. Else it can be a security issue (buying your own product).
When I load, I get this annoying exception. Absolutely no help on any website.

Finally after a few hours of pulling out some more of my hair, I finally think of a root cause. The main reason that its a security issue can be only because of the public key or the test account. Thats it, it was the test account.

Root Cause 1
My registered account (A) with market place was my primary account with all the app’s, contacts and my life in short. The test account was my other gmail account (B), which did not have any apps. So, catch 22.

If I setup (A) as my primary account on android phone (samsung, which does not take its updates from google android, buts its own builds), then I land up in a Security Exception since A cannot be used as a test account. And the primary account on the device is considered as the test account when the sample in app billing app runs.

If I setup (B) as my primary account on the android phone, market application is 2.1, and not enough for the sample app to run. So you see, catch 22.

Solution was simple. I registered B as my market account (one more cost to my budget :)). But google being really nice, refunded my fee’s for A.

Mind you A was a new account, no apps published on this account and nothing pending for payment. It was a brand new account.

Root Cause 2
The public key can change when google activates/cancels accounts. So just reverify the public key and your Security.java file.

Root Cause 3 (THE worst of the root causes)
The AIDL file is referred from your BillingService.java file. Also remember that we modified the package name to “not” contain android ? The BillingService is “INCORRECTLY” referring to the older package (com.android…..).
Now, how do I know this ? Well, details are in the fine print. On the “http://developer.android.com/guide/market/billing/billing_integrate.html&#8221; page its mentioned that if you need debugging information set DEBUG = true in Consts.java. I did that and found a warning , before the SecurityException in LogCat.

Set Debug=true in Consts.java

Hope you understood it. If not, please comment on the blog, I’ll respond.