In App Purchase in Android
What is the use of Google in App Purchase in Android?
If we want to sell some digital contents, media (photos, videos etc) from your app then Google provide this facility in the form of Google InAppPurchase.
- You can buy a new vehicle while playing a game, you can buy a sword which makes a more powerful to your game.
- You can purchase the unlocking key, which enables the more feature to your app.
- Virtual currency which helps to you purchases the products.
# Redeem the in-app promotional codes
Google InApp purchase allows you, redeem the promotional codes while purchasing some in-app items on play store in android device.
Process for redeeming the code
- Click the drop-down next to item price on a dialog.
- Enter the promotional code.
- Follow the given instruction.
# Implementation steps for Google InAppPurchase.
- Check the “Google play billing library” package is installed in your Android Studio, if not then install it.
- After success full installation, InAppBillingService.aidl , Sample code & other data are available in play_ billing folder. Which is located at your SDK location. (C:\Android\sdk\google\play_billing), check your SDK location path.
- Create the new project in Android Studio.
- Copy the IInAppBlllingService.aidl library from billing (C:\Android\sdk\google\play_billing\samples\TrivialDrive\src\com\andriod\vending\billing) fold
- Paste it into your source folder by creating a new folder.
- Copy the other source file from util folder. (C:\Android\sdk\google\play_billing\samples\TrivialDrive\src\com\example\android\trivialdrivesample\util) folder paste it in new folder by creating it, under the src folder.
- In Our main class write the respective code for in App Billing, with the help of Iab Helper. Use the override methods & listener of Iab Helper with.
static final String ITEM_SKU = “test purpose/live purpose”;
IabHelper iabHelper = new IabHelper(this, base64EncodedPublicKey);
- For getting the “base64EncodedPublicKey”, we have to create the app on Google play store account, under the Services & APIs we get the base64EncodedPublicKey.
Without any space, we have to copy & paste in main java file.
Explanation of ITEM_SKU:
- ITEM_SKU is nothing but main product Id, we have to put it in main java file.
- We can use it for two scenarios, one for testing mode & one for live mode.
- For test mode, you can use any ITEM_SKU, & upload the apk. you can get the testing results. (Just open a window with test success full message, but actual transaction is not done)
# SECTION B
- Use actual product id, for ITEM_SKU, it’s getting after adding the product under “In-app Products” & upload the apk on play store.
- After successfully coding generate the signed apk, & upload it on play store.
- After the uploading the apk. You can manage the In-app products under the “In-app Products” left-hand side & make it an active product
with ITEM_SKU SECTION A or SECTION B.
- After successfully done this all above steps, you can enjoy the selling your digital contents in-app on Android device.
!! Happy Coding !!