Implementing In-app Billing Android
Implementing In-app Billing
SRC: https://developer.android.com/google/play/billing/billing_integrate.html#billing-service
Code Available at Github: https://github.com/VishalJogiya/InAppExample/tree/master
An Important page to implement in-app purchases in your android app.
Many tutorial in google documentation itself makes it confusing, which one to follow. So I, Framed this page here which include everthing you want.
In this document
- Adding the AIDL file
- Updating your manifest
- Creating a ServiceConnection
- Making In-app Billing requests
- Securing your app
Reference
Related Samples
See also
Note: To see a complete implementation and learn how to test your application, see the Selling In-app Products training class. The training class provides a complete sample In-app Billing application, including convenience classes to handle key tasks that are related to setting up your connection, sending billing requests, processing responses from Google Play, and managing background threading so that you can make In-app Billing calls from your main activity.
Before you start, read the In-app Billing Overview to familiarize yourself with concepts that make it easier for you to implement In-app Billing.
Complete these steps to implement In-app Billing in your application:
- Add the In-app Billing library to your project.
- Update your
AndroidManifest.xml
file. - Create a
ServiceConnection
and bind it to theIInAppBillingService
. - Send In-app Billing requests from your application to
IInAppBillingService
. - Handle In-app Billing responses from Google Play.
Adding the AIDL file to your project
The
IInAppBillingService.aidl
is an Android Interface Definition Language (AIDL) file that defines the interface to the In-app Billing Version 3 service. You can use this interface to make billing requests by invoking interprocess communication (IPC) method calls.
You can find the
IInAppBillingService.aidl
file in the Trivial Drive sample app. To add the In-app Billing library to your project, follow these instructions:- In Android Studio, import the
IInAppBillingService.aidl
file to your project as described in the following steps:- Create a directory named aidl under
src/main
. - Add a new package
com.android.vending.billing
in this directory. - Import the
IInAppBillingService.aidl
file into this package.
- Create a directory named aidl under
- Build your application. You should see a generated file named
IInAppBillingService.java
in thegen/
directory of your project. - Add the helper classes from the util/ directory of the Trivial Drive sample to your project. Remember to change the package name declarations in those files accordingly so that your project compiles.
Updating your app's manifest
In-app billing relies on the Google Play application, which handles all of the communication between your application and the Google Play server. To use the Google Play application, your application must request the proper permission. You can do this by adding the
com.android.vending.BILLING
permission to your AndroidManifest.xml file. If your application does not declare the In-app Billing permission, but attempts to send billing requests, Google Play refuses the requests and responds with an error.
To give your app the necessary permission, add this line in the
AndroidManifest.xml
file:<uses-permission android:name="com.android.vending.BILLING" />
Comments
Post a Comment