Hi all,

I have already showed you how to implement in app purchase in Android.
Please go through this post before reading this article.

Android IN App Purchase

This is how the MainActivity source code will look like.

package com.coderzheaven.inappdemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

import com.coderzheaven.android.util.IabHelper;
import com.coderzheaven.inapp.InAppPurchase;
import com.coderzheaven.inapp.InAppStateListener;

public class MainActivity extends Activity implements OnClickListener,
		InAppStateListener {

	static final String TAG = "INAPPTESTING";

	IabHelper mHelper;
	InAppPurchase inapp;
	static String SKU_INAPPITEM_ID = "android.test.purchased";

	protected void onCreate(Bundle savedInstanceState) {


	public void onClick(View v) {

		if (v.getId() == R.id.button_query) {

			showToast("Querying Items");
			inapp = new InAppPurchase(this, this, SKU_INAPPITEM_ID);
			mHelper = inapp.QueryInventry();

		} else {

			if (inapp != null)
				showToast("Please click query items before purchasing");



	public void showToast(String msg) {
		Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
				+ data);

		// Pass on the activity result to the helper for handling
		if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
			// not handled, so handle it ourselves (here's where you'd
			// perform any handling of activity results not related to in-app
			// billing...
			super.onActivityResult(requestCode, resultCode, data);
		} else {
			Log.d(TAG, "onActivityResult handled by IABUtil.");


	public void onInAppInitialiseError() {
		showToast("In App initialise Error.");

	public void onInAppInitialiseSuccess() {
		showToast("In App initialise Success.");

	public void onQueryInventryCompleted() {
		//showToast("Querying Items Completed.");

	public void onQueryInventryError(String message) {
		System.out.println("onQueryInventryError : ");
		showToast("Querying Items Error.");

	public void onAlreadyPurchased(String inappItemID) {
		showToast("Item already Purchased.");

	public void onItemNotPurchased(String inappItemID) {
		System.out.println("onItemNotPurchased : " + inappItemID);
		showToast("Item not purchased");

	public void onPurchaseSuccessfull(String inappItemID) {
		System.out.println("onPurchaseSuccessfull : " + inappItemID);
		showToast("Purchase Successful");

	public void onPurchaseError(String inappItemID, String message) {
		System.out.println("onPurchaseError : " + inappItemID);
		showToast("Purchase Error");


You can download the complete source code from here itself.


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.