Tutorial details

How to Integrate In App Purchase Billing in Android | App Code for Sale | Preview

How to Integrate In App Purchase Billing in Android | Android Tutorial

Make money with In App Purchase in Android

Overview PAGE TOP

Hello Friends! Today I am going to share very useful blog for In App Purchase in Android. Google provide In App Billing faculty in Android. In App Purchase is a very easy and secure way for make payment online. Please follow my blog step by step:

Screen Shot

chok.JPG

PA.JPG

  1. Create a new Project in Android.
  2. Create MainActivity.java class.
  3. Add activity_main.xml in your res/layout folder.
  4. Add Billing services and permission in Manifest.xml.

Do’s

  1. Create sign apk for your application.
  2. Upload your apk on Google play store.
  3. Create product for your application.
  4. wait for 6-12 hour for update item’s on store.
  5. Copy Key of your Google account and paste it into BillingSecurity.java class Line number 135-

    1 String base64EncodedPublicKey = "PUT YOUR PUBLIC KEY HERE";

  6. Give Billing permissions in Manifest.xml

  7. Add

    1 IMarketBillingService.java in com.android.vending.billing package.

Don’t

  1. Don’t use emulator for testing its does not support Billing Services.
  2. Don’t use unsigned apk for Billing services.
  3. Don’t share your key with any one.

My Code-

1)MainActivity.java

01  package com.manish.inapppurchase;
02  
03  import android.app.Activity;
04  import android.content.Context;
05  import android.content.Intent;
06  import android.os.Bundle;
07  import android.os.Handler;
08  import android.util.Log;
09  import android.view.View;
10  import android.view.View.OnClickListener;
11  import android.widget.Button;
12  import android.widget.Toast;
13  
14  public class MainActivity extends Activity implements OnClickListener {
15   Button btn1, btn2, btn3;
16   private Context mContext=this;
17   private static final String TAG = "Android BillingService";
18   @Override
19   protected void onCreate(Bundle savedInstanceState) {
20    super.onCreate(savedInstanceState);
21    setContentView(R.layout.activity_main);
22    btn1 = (Button) findViewById(R.id.button1);
23    btn2 = (Button) findViewById(R.id.button2);
24    btn3 = (Button) findViewById(R.id.button3);
25    btn1.setOnClickListener(this);
26    btn2.setOnClickListener(this);
27    btn3.setOnClickListener(this);
28     
29     startService(new Intent(mContext, BillingService.class));
30           BillingHelper.setCompletedHandler(mTransactionHandler);
31   }
32   public Handler mTransactionHandler = new Handler(){
33    public void handleMessage(android.os.Message msg) {
34     Log.i(TAG, "Transaction complete");
35     Log.i(TAG, "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
36     Log.i(TAG, "Item purchased is: "+BillingHelper.latestPurchase.productId);
37      
38     if(BillingHelper.latestPurchase.isPurchased()){
39      showItem();
40     }
41    };
42    
43  };
44   @Override
45   public void onClick(View v) {
46    if (v == btn1) {
47     if(BillingHelper.isBillingSupported()){
48      BillingHelper.requestPurchase(mContext, "android.test.purchased");
49           } else {
50            Log.i(TAG,"Can't purchase on this device");
51            btn1.setEnabled(false); // XXX press button before service started will disable when it shouldnt
52           }
53     Toast.makeText(this, "Shirt Button", Toast.LENGTH_SHORT).show();
54    }
55    if (v == btn2) {
56     if(BillingHelper.isBillingSupported()){
57      BillingHelper.requestPurchase(mContext, "android.test.purchased");
58           } else {
59            Log.i(TAG,"Can't purchase on this device");
60            btn2.setEnabled(false); // XXX press button before service started will disable when it shouldnt
61           }
62     Toast.makeText(this, "TShirt Button", Toast.LENGTH_SHORT).show();
63    }
64    if (v == btn3) {
65     if(BillingHelper.isBillingSupported()){
66      BillingHelper.requestPurchase(mContext, "android.test.purchased");
67           } else {
68            Log.i(TAG,"Can't purchase on this device");
69            btn3.setEnabled(false); // XXX press button before service started will disable when it shouldnt
70           }
71     Toast.makeText(this, "Denim Button", Toast.LENGTH_SHORT).show();
72    }
73  
74   }
75  
76   private void showItem() {
77    //purchaseableItem.setVisibility(View.VISIBLE);
78   }
79  
80   @Override
81   protected void onPause() {
82    Log.i(TAG, "onPause())");
83    super.onPause();
84   }
85    
86   @Override
87   protected void onDestroy() {
88    BillingHelper.stopService();
89    super.onDestroy();
90   }
91  }

2)activity_main.xml

01  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
02      xmlns:tools="http://schemas.android.com/tools"
03      android:layout_width="match_parent"
04      android:layout_height="match_parent"
05      android:background="#0099CC"
06      tools:context=".MainActivity" >
07  
08      <Button
09          android:id="@+id/button1"
10          android:layout_width="150dp"
11          android:layout_height="35dp"
12          android:layout_alignParentTop="true"
13          android:layout_centerHorizontal="true"
14          android:layout_marginTop="40dp"
15          android:background="#FFFFFF"
16          android:text="Shirt for 5.4$" />
17  
18      <Button
19          android:id="@+id/button2"
20          android:layout_width="150dp"
21          android:layout_height="35dp"
22          android:layout_below="@+id/button1"
23          android:layout_centerHorizontal="true"
24          android:layout_marginTop="10dp"
25          android:background="#FFFFFF"
26          android:text="Tshirt for 7.4$" />
27  
28      <Button
29          android:id="@+id/button3"
30          android:layout_width="150dp"
31          android:layout_height="35dp"
32          android:layout_below="@+id/button2"
33          android:layout_centerHorizontal="true"
34          android:layout_marginTop="10dp"
35          android:background="#FFFFFF"
36          android:text="Denim for 10.7$" />
37  
38  </RelativeLayout>

3)manifest.xml

01  <?xml version="1.0" encoding="utf-8"?>
02  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
03      package="com.manish.inapppurchase"
04      android:versionCode="1"
05      android:versionName="1.0" >
06  
07      <uses-sdk
08          android:minSdkVersion="7"
09          android:targetSdkVersion="16" />
10  
11      <uses-permission android:name="com.android.vending.BILLING" />
12      <uses-permission android:name="android.permission.INTERNET" />
13  
14      <application
15          android:allowBackup="true"
16          android:icon="@drawable/ic_launcher"
17          android:label="@string/app_name"
18          android:theme="@style/AppTheme" >
19          <activity
20              android:name="com.manish.inapppurchase.MainActivity"
21              android:label="@string/app_name" >
22              <intent-filter>
23                  <action android:name="android.intent.action.MAIN" />
24  
25                  <category android:name="android.intent.category.LAUNCHER" />
26              </intent-filter>
27          </activity>
28  
29          <service android:name=".BillingService" />
30  
31          <receiver android:name=".BillingReceiver" >
32              <intent-filter>
33                  <action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
34                  <action android:name="com.android.vending.billing.RESPONSE_CODE" />
35                  <action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
36              </intent-filter>
37          </receiver>
38      </application>
39  
40  </manifest>

4) Zip Code

Reference PAGE TOP

http://www.javacodegeeks.com/2013/05/how-to-integrate-in-app-purchase-billing-in-android.html

3 Comments Leave a comment

Please login in order to leave a comment.

Newest first
  • sagar_raiyani 2014-08-14 06:51:07 Thread #247

    Hello....

    Zip code link is not working.....

  • AamirZaptech 2013-11-26 14:01:52 Thread #56

    InComplete code,I am not able to find any zip code or BillingService.java file is not there in your tutorial.

  • mathewmdy 2013-11-18 07:47:53 Thread #55

    Code is not complete how can one build an application with this tutorial?

!

Sign-in to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.