RSS

Android In App Purchase Tutorial

Android In App Purchase

Android In App Purchase

To implement in app billing in android this example is quiet simple and easy to handle at first .. the things you have to do are:

http://blog.blundell-apps.com/simple-inapp-billing-payment/

  1. download the sample project code from the above link (Having Description of code and download link at bottom)
  2. in your android project where you want to implement in app billing, create package com.android.vending.billing and place IMarketBillingService.aidl (you can find this and all files mention below in the project you downloaded in step 1)
  3. place following utility files in any package and correct import statements accordingly.
          * BillingHelper.java
          * BillingReceiver.java
          * BillingSecurity.java
          * BillingService.java
          * C.java
    
  4. place the public key (you can find it in developer console in the bottom section of edit profile) in the BillingSecurity.java in line saying
    String base64EncodedPublicKey = "your public key here"
  5. Declare the following permission (outside the application tag), service and receiver (Inside the application tag) in your manifest like shown below(can also see manifest which is along the code for reference)
     //outside the application tag 
     <uses-permission android:name="com.android.vending.BILLING" />
    
     // Inside the application tag
     <service android:name=".BillingService" />
    
    <receiver android:name=".BillingReceiver">
        <intent-filter>
            <action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
            <action android:name="com.android.vending.billing.RESPONSE_CODE" />
            <action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />            
        </intent-filter>
    </receiver> 
    
  6. place the following code as mentioned with there places in your activity where purchase is being held.
    //at the starting of your onCreate()
    startService(new Intent(mContext, BillingService.class));
    BillingHelper.setCompletedHandler(mTransactionHandler);
    
    //outside onCreate() Within class
     public Handler mTransactionHandler = new Handler(){
        public void handleMessage(android.os.Message msg) {
            Log.i(TAG, "Transaction complete");
            Log.i(TAG, "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
            Log.i(TAG, "Item purchased is: "+BillingHelper.latestPurchase.productId);
    
            if(BillingHelper.latestPurchase.isPurchased()){
                //code here which is to be performed after successful purchase
            }
        };
    
     };
    
     //code to initiate a purchase... can be placed in onClickListener etc
      if(BillingHelper.isBillingSupported()){
            BillingHelper.requestPurchase(mContext, "android.test.purchased"); 
            // where android.test.purchased is test id for fake purchase, when you create
    // products through developer console you can set a code to pass the id(which is given on
    // developer console while creating a product) of the item which is selected for purchase
    // to initiate purchase of that item.
        } else {
            Log.i(TAG,"Can't purchase on this device");
             // Do Anything Heer to show user that purchase not possible on this device
        }
    

Note: To do a test purchase you need to put the public key in BillingSecurity.java as mentioned above secondly you need to upload the apk to the developer console(you can leave it uupublished and unactive) and thirdly you need a real android device(emulator wouldn't work) having updated play store app.

Note: the account needed for in app purchase and described in all above discussion is not just simple publisher account its publisher account embedded with google merchant wallet account. The details can be found in link below.

http://support.google.com/googleplay/android-developer/bin/answer.py?hl=en&answer=113468

 
2 Comments

Posted by on September 27, 2012 in Android Devalopement

 

Tags: , ,

Customizaing Seekbar Android

Demo Slide Show

This slideshow requires JavaScript.

Demo Video

Here is one of simple and interesting App i developed during android training at job. This App containing the idea where there are three containers of basic colors (Red, Green, Blue)  first the containers start to fill from 0-255 as the basic different levels of a color shade while background also changing its color as the containers quantity fills. At the end the background becomes black where from customized seek bars you can put quantity from containers to the black background and view what color will be there by mixing different quantities of different colors. Here is the link of zip file containg complete project http://www.mediafire.com/download/doh5re3d3gwg898/ColorUp.zip .

 
2 Comments

Posted by on September 21, 2011 in Android Intresting Apps

 

Tags: , ,

 
Follow

Get every new post delivered to your Inbox.