public class IabHelper extends Object
startSetup(com.creativemobile.dragracing.payment.google.util.IabHelper.OnIabSetupFinishedListener) method and provide a
listener; that listener will be notified when setup is complete, after which (and not before) you may call other methods.
After setup is complete, you will typically want to request an inventory of owned items and subscriptions. See queryInventory(boolean, java.util.List<java.lang.String>),
queryInventoryAsync(boolean, java.util.List<java.lang.String>, com.creativemobile.dragracing.payment.google.util.IabHelper.QueryInventoryFinishedListener) and related methods.
When you are done with this object, don't forget to call dispose() to ensure proper cleanup. This object holds a binding to the in-app
billing service, which will leak unless you dispose of it correctly. If you created the object on an Activity's onCreate method, then the
recommended place to dispose of it is the Activity's onDestroy method.
A note about threading: When using this object from a background thread, you may call the blocking versions of methods; when using from a UI
thread, call only the asynchronous versions and handle the results via callbacks. Also, notice that you can only call one asynchronous operation at
a time; attempting to start a second asynchronous operation while the first one has not yet completed will result in an exception being thrown.| Modifier and Type | Class and Description |
|---|---|
static interface |
IabHelper.OnConsumeFinishedListener
Callback that notifies when a consumption operation finishes.
|
static interface |
IabHelper.OnConsumeMultiFinishedListener
Callback that notifies when a multi-item consumption operation finishes.
|
static interface |
IabHelper.OnIabPurchaseFinishedListener
Callback that notifies when a purchase is finished.
|
static interface |
IabHelper.OnIabSetupFinishedListener
Callback for setup process.
|
static interface |
IabHelper.QueryInventoryFinishedListener
Listener that notifies when an inventory query operation completes.
|
| Constructor and Description |
|---|
IabHelper(android.content.Context ctx,
String base64PublicKey)
Creates an instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
consumeAsync(List<Purchase> purchases,
IabHelper.OnConsumeMultiFinishedListener listener)
Same as
consumeAsync, but for multiple items at once. |
void |
consumeAsync(Purchase purchase,
IabHelper.OnConsumeFinishedListener listener)
Asynchronous wrapper to item consumption.
|
void |
dispose()
Dispose of object, releasing resources.
|
void |
enableDebugLogging(boolean enable) |
void |
enableDebugLogging(boolean enable,
String tag)
Enables or disable debug logging through LogCat.
|
static String |
getResponseDesc(int code)
Returns a human-readable description for the given response code.
|
boolean |
handleActivityResult(int requestCode,
int resultCode,
android.content.Intent data)
Handles an activity result that's part of the purchase flow in in-app billing.
|
void |
launchPurchaseFlow(android.app.Activity act,
String sku,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener) |
void |
launchPurchaseFlow(android.app.Activity act,
String sku,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener,
String extraData) |
void |
launchPurchaseFlow(android.app.Activity act,
String sku,
String itemType,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener,
String extraData)
Initiate the UI flow for an in-app purchase.
|
void |
launchSubscriptionPurchaseFlow(android.app.Activity act,
String sku,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener) |
void |
launchSubscriptionPurchaseFlow(android.app.Activity act,
String sku,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener,
String extraData) |
Inventory |
queryInventory(boolean querySkuDetails,
List<String> moreSkus) |
Inventory |
queryInventory(boolean querySkuDetails,
List<String> moreItemSkus,
List<String> moreSubsSkus)
Queries the inventory.
|
void |
queryInventoryAsync(boolean querySkuDetails,
IabHelper.QueryInventoryFinishedListener listener) |
void |
queryInventoryAsync(boolean querySkuDetails,
List<String> moreSkus,
IabHelper.QueryInventoryFinishedListener listener)
Asynchronous wrapper for inventory query.
|
void |
queryInventoryAsync(IabHelper.QueryInventoryFinishedListener listener) |
void |
startSetup(IabHelper.OnIabSetupFinishedListener listener)
Starts the setup process.
|
boolean |
subscriptionsSupported()
Returns whether subscriptions are supported.
|
public static final int BILLING_RESPONSE_RESULT_OK
public static final int BILLING_RESPONSE_RESULT_USER_CANCELED
public static final int BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE
public static final int BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE
public static final int BILLING_RESPONSE_RESULT_DEVELOPER_ERROR
public static final int BILLING_RESPONSE_RESULT_ERROR
public static final int BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED
public static final int BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED
public static final int IABHELPER_ERROR_BASE
public static final int IABHELPER_REMOTE_EXCEPTION
public static final int IABHELPER_BAD_RESPONSE
public static final int IABHELPER_VERIFICATION_FAILED
public static final int IABHELPER_SEND_INTENT_FAILED
public static final int IABHELPER_USER_CANCELLED
public static final int IABHELPER_UNKNOWN_PURCHASE_RESPONSE
public static final int IABHELPER_MISSING_TOKEN
public static final int IABHELPER_UNKNOWN_ERROR
public static final int IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE
public static final int IABHELPER_INVALID_CONSUMPTION
public static final String RESPONSE_CODE
public static final String RESPONSE_GET_SKU_DETAILS_LIST
public static final String RESPONSE_BUY_INTENT
public static final String RESPONSE_INAPP_PURCHASE_DATA
public static final String RESPONSE_INAPP_SIGNATURE
public static final String RESPONSE_INAPP_ITEM_LIST
public static final String RESPONSE_INAPP_PURCHASE_DATA_LIST
public static final String RESPONSE_INAPP_SIGNATURE_LIST
public static final String INAPP_CONTINUATION_TOKEN
public static final String ITEM_TYPE_INAPP
public static final String ITEM_TYPE_SUBS
public static final String GET_SKU_DETAILS_ITEM_LIST
public static final String GET_SKU_DETAILS_ITEM_TYPE_LIST
public IabHelper(android.content.Context ctx,
String base64PublicKey)
startSetup(com.creativemobile.dragracing.payment.google.util.IabHelper.OnIabSetupFinishedListener) and wait for setup
to complete. This constructor does not block and is safe to call from a UI thread.ctx - Your application or Activity context. Needed to bind to the in-app billing service.base64PublicKey - Your application's public key, encoded in base64. This is used for verification of purchase signatures. You can find your app's
base64-encoded public key in your application's page on Google Play Developer Console. Note that this is NOT your
"developer public key".public void enableDebugLogging(boolean enable,
String tag)
public void enableDebugLogging(boolean enable)
public void startSetup(IabHelper.OnIabSetupFinishedListener listener)
listener - The listener to notify when the setup process is complete.public void dispose()
public boolean subscriptionsSupported()
public void launchPurchaseFlow(android.app.Activity act,
String sku,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener)
public void launchPurchaseFlow(android.app.Activity act,
String sku,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener,
String extraData)
public void launchSubscriptionPurchaseFlow(android.app.Activity act,
String sku,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener)
public void launchSubscriptionPurchaseFlow(android.app.Activity act,
String sku,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener,
String extraData)
public void launchPurchaseFlow(android.app.Activity act,
String sku,
String itemType,
int requestCode,
IabHelper.OnIabPurchaseFinishedListener listener,
String extraData)
Activity.onActivityResult(int, int, android.content.Intent) method, at which point you must call this object's handleActivityResult(int, int, android.content.Intent) method to
continue the purchase flow. This method MUST be called from the UI thread of the Activity.act - The calling activity.sku - The sku of the item to purchase.itemType - indicates if it's a product or a subscription (ITEM_TYPE_INAPP or ITEM_TYPE_SUBS)requestCode - A request code (to differentiate from other responses -- as in Activity.startActivityForResult(android.content.Intent, int)).listener - The listener to notify when the purchase process finishesextraData - Extra data (developer payload), which will be returned with the purchase data when the purchase completes. This extra data will be
permanently bound to that purchase and will always be returned when the purchase is queried.public boolean handleActivityResult(int requestCode,
int resultCode,
android.content.Intent data)
launchPurchaseFlow(android.app.Activity, java.lang.String, int, com.creativemobile.dragracing.payment.google.util.IabHelper.OnIabPurchaseFinishedListener), then you must
call this method from your Activity's android.app.Activity@onActivityResult method. This method MUST be called from the UI thread of
the Activity.requestCode - The requestCode as you received it.resultCode - The resultCode as you received it.data - The data (Intent) as you received it.public Inventory queryInventory(boolean querySkuDetails, List<String> moreSkus) throws IabException
IabExceptionpublic Inventory queryInventory(boolean querySkuDetails, List<String> moreItemSkus, List<String> moreSubsSkus) throws IabException
#refreshInventoryAsync.querySkuDetails - if true, SKU details (price, description, etc) will be queried as well as purchase information.moreItemSkus - additional PRODUCT skus to query information on, regardless of ownership. Ignored if null or if querySkuDetails is false.moreSubsSkus - additional SUBSCRIPTIONS skus to query information on, regardless of ownership. Ignored if null or if querySkuDetails is false.IabException - if a problem occurs while refreshing the inventory.public void queryInventoryAsync(boolean querySkuDetails,
List<String> moreSkus,
IabHelper.QueryInventoryFinishedListener listener)
queryInventory(boolean, java.util.List<java.lang.String>), but will do so
asynchronously and call back the specified listener upon completion. This method is safe to call from a UI thread.querySkuDetails - as in queryInventory(boolean, java.util.List<java.lang.String>)moreSkus - as in queryInventory(boolean, java.util.List<java.lang.String>)listener - The listener to notify when the refresh operation completes.public void queryInventoryAsync(IabHelper.QueryInventoryFinishedListener listener)
public void queryInventoryAsync(boolean querySkuDetails,
IabHelper.QueryInventoryFinishedListener listener)
public void consumeAsync(Purchase purchase, IabHelper.OnConsumeFinishedListener listener)
consume(com.creativemobile.dragracing.payment.google.util.Purchase), but performs the consumption in the background and notifies completion
through the provided listener. This method is safe to call from a UI thread.purchase - The purchase to be consumed.listener - The listener to notify when the consumption operation finishes.public void consumeAsync(List<Purchase> purchases, IabHelper.OnConsumeMultiFinishedListener listener)
consumeAsync, but for multiple items at once.purchases - The list of PurchaseInfo objects representing the purchases to consume.listener - The listener to notify when the consumption operation finishes.public static String getResponseDesc(int code)
code - The response codeCopyright © 2016 Creative Mobile. All rights reserved.