top of page
  • Writer's pictureObsidian Soft

How to use Google IAP v3 for Beginners (Part 1)

Updated: Jun 1, 2020

You may have monetized your apps with only ads but you may be seeing a fall in your revenue. The reason for this is that more and more people don't want to see ads in their apps especially apps targeting children. These people are willing to buy apps just to avoid seeing ads. So, indie developers like me have to change our strategy.

We have two options: either offer the complete app free with ads and offer an In App Purchase (IAP) to remove the ads or offer only part of the app free with an In App Purchase to unlock the full version of it.


Now, I will explain in detail how I added IAP to my app Phonics Fun to remove ads using Android Studio. I will

cover each and every step so that it can be followed by even the beginners to android development.


Adding Billing Permission:


First, you need to add this permission to your app's manifest file.

 <uses-permission android:name="com.android.vending.BILLING" />

Make sure to increase the version code in the manifest file if you already have a published release in the play store. Build a signed apk/bundle.


You need to upload this newly built apk in the closed track testing. Go to your Google developer console. Choose your app -> Release Management -> App Releases. In Closed Track section, press Manage button in front of Alpha and follow the instructions to create a release. Make sure that you add at least one tester gmail address and it should not be the same as your developer account. This account will be used to test your IAP.


The good thing is that you don't have to wait for your release to be published. You just have to upload the apk with the billing permission and then, you will be allowed to add an IAP product.


Adding IAP Product:


To add your IAP product, choose your app in the dashboard->Store presence->In-app products->Managed Products


Now, click on CREATE MANAGED PRODUCT:

Managed product means those IAP products that require a one time payment such as removing ads, unlocking full version of the app, etc.




Product ID is the most important element of your IAP product. You need to have a unique product ID so I would recommend some text added to your app's package name such as

com.example.myapp.removeads where com.example.myapp is your app's package name.

The product ID is the same as SKU and they can be used interchangeably. The remaining form for adding a managed product is self explanatory. You need to add a title which will be displayed to the user when he/she starts purchasing your IAP and you also need to have a price for your IAP product 😊.


Remember to make the IAP product active.


IAP Purchase Helper Code:


Now, I will come to the coding part which may seem complicated but it is essentially just copy paste 😉.


Google has already provided the sample code using an example app called "Trivial Drive". The sample code also covers other IAP products types such as subscriptions but I will not cover that type here.


I will assume here that your app's package name is com.example.myapp.


First, increase the version code of your app again in the manifest file.


You need to add a util folder that will contain all your IAP helper code. In the project view of Android Studio, go to app->src->main->java. (You may have a different view and may see app->java instead.) Right lick on com.example.myapp (this will be the package name of your app. Choose New->Package and name it util.


Next, you have to create the following java classes in this util package. Be careful to use the exact names otherwise you will have a gazillion errors 😉. I am uploading the files here. Start creating each file one by one in the newly created util package.


Right click on util->New->Java Class. Name it appropriately and then, open the corresponding file with that name and copy paste the code from that file to your newly created java class file. I have added the package name com.example.myapp.util in each file but you will need to update it to your own package.



1. IabException.java

IabException
.rtf
Download RTF • 2KB

2. IabHelper.java

IabHelper
.rtf
Download RTF • 56KB

3. Security.java

Security
.rtf
Download RTF • 6KB

4. Inventory.java

Inventory
.rtf
Download RTF • 4KB

5. IabBroadcastReceiver.java

IabBroadcastReceiver
.rtf
Download RTF • 3KB

6. Purchase.java

Purchase
.rtf
Download RTF • 3KB

7. IabResult.java

IabResult
.rtf
Download RTF • 2KB

8. SkuDetails.java

SkuDetails
.rtf
Download RTF • 3KB

Now, you are more than halfway through so give yourself a clap on the back and take a break for a cup of tea or coffee 😉.



14 views0 comments

Recent Posts

See All
bottom of page