The In-app Billing API has been recently updated to version 3. This library is currently for version 2 only, and will be updated in early 2013.
Android Billing Library
That's how simple it should be to use Android In-app Billing.
And with this library it is.
Android Billing Library implements in-app billing's full specification and offers high-level classes to use it. Transactions are stored in a local obfuscated database which can be easily queried.
Get acquainted with the Android In-app Billing documentation.
Add Android Billing Library to your project.
Open the AndroidManifest.xml of your application and add this permission...
<uses-permission android:name="com.android.vending.BILLING" />
...and this service and receiver inside the application element:
<service android:name="net.robotmedia.billing.BillingService" /> <receiver android:name="net.robotmedia.billing.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>
- Subclass AbstractBillingActivity in the activity in which you want to use in-app billing. Or use BillingController if you need finer-grain control.
AbstractBillingActivity is an abstract activity that provides default integration with in-app billing (an analogous class for fragments is also provided). It is useful to get acquainted with the library, or for very simple applications that require in-app billing integration in only one activity. For more flexibility use BillingController directly.
When created your AbstractBillingActivity instance will check if in-app billing is supported, followed by a call to
onBillingChecked(boolean), which has to be implemented by the subclass.
Additionally, your AbstractBillingActivity subclass will attempt to restore all transactions, only once. This is necessary in case the user has previously installed the app and made purchases. Existing transactions will generate calls to
onPurchaseStateChange(String, PurchaseState), which has to be implemented by the subclass.
Starting a purchase is as simple as calling
requestPurchase(String). AbstractBillingActivity will start the Google Play intent automatically and
onPurchaseStateChange(String, PurchaseState) will be called after the transaction is confirmed.
If you override any of the methods provided by AbstractBillingActivity, make sure to call the superclass implementation.
BillingController provides high-level functions to interact with the Billing service and to query an obfuscated local transaction database.
Additionally, BillingController requires a
BillingController.IConfiguration instance from which the public key required to validate signed messages and a salt to obfuscate transactions are obtained. A good place to provide the configuration is in the
It should be noted that Dungeons Redux does not intend to be an example of how to use in-app billing in general.
Copyright 2011 Robot Media SL (http://www.robotmedia.net)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.