Search in sources :

Example 1 with Inventory

use of com.onesignal.example.iap.Inventory in project OneSignal-Android-SDK by OneSignal.

the class IabHelper method queryInventoryAsync.

/**
     * Asynchronous wrapper for inventory query. This will perform an inventory
     * query as described in {@link #queryInventory}, but will do so asynchronously
     * and call back the specified listener upon completion. This method is safe to
     * call from a UI thread.
     *
     * @param querySkuDetails as in {@link #queryInventory}
     * @param moreSkus as in {@link #queryInventory}
     * @param listener The listener to notify when the refresh operation completes.
     */
public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreSkus, final QueryInventoryFinishedListener listener) {
    final Handler handler = new Handler();
    checkNotDisposed();
    checkSetupDone("queryInventory");
    flagStartAsync("refresh inventory");
    (new Thread(new Runnable() {

        public void run() {
            IabResult result = new IabResult(BILLING_RESPONSE_RESULT_OK, "Inventory refresh successful.");
            Inventory inv = null;
            try {
                inv = queryInventory(querySkuDetails, moreSkus);
            } catch (IabException ex) {
                result = ex.getResult();
            }
            flagEndAsync();
            final IabResult result_f = result;
            final Inventory inv_f = inv;
            if (!mDisposed && listener != null) {
                handler.post(new Runnable() {

                    public void run() {
                        listener.onQueryInventoryFinished(result_f, inv_f);
                    }
                });
            }
        }
    })).start();
}
Also used : Handler(android.os.Handler) IabException(com.onesignal.example.iap.IabException) IabResult(com.onesignal.example.iap.IabResult) Inventory(com.onesignal.example.iap.Inventory)

Example 2 with Inventory

use of com.onesignal.example.iap.Inventory in project OneSignal-Android-SDK by OneSignal.

the class IabHelper method queryInventory.

/**
     * Queries the inventory. This will query all owned items from the server, as well as
     * information on additional skus, if specified. This method may block or take long to execute.
     * Do not call from a UI thread. For that, use the non-blocking version {@link #refreshInventoryAsync}.
     *
     * @param querySkuDetails if true, SKU details (price, description, etc) will be queried as well
     *     as purchase information.
     * @param moreItemSkus additional PRODUCT skus to query information on, regardless of ownership.
     *     Ignored if null or if querySkuDetails is false.
     * @param moreSubsSkus additional SUBSCRIPTIONS skus to query information on, regardless of ownership.
     *     Ignored if null or if querySkuDetails is false.
     * @throws IabException if a problem occurs while refreshing the inventory.
     */
public Inventory queryInventory(boolean querySkuDetails, List<String> moreItemSkus, List<String> moreSubsSkus) throws IabException {
    checkNotDisposed();
    checkSetupDone("queryInventory");
    try {
        Inventory inv = new Inventory();
        int r = queryPurchases(inv, ITEM_TYPE_INAPP);
        if (r != BILLING_RESPONSE_RESULT_OK) {
            throw new IabException(r, "Error refreshing inventory (querying owned items).");
        }
        if (querySkuDetails) {
            r = querySkuDetails(ITEM_TYPE_INAPP, inv, moreItemSkus);
            if (r != BILLING_RESPONSE_RESULT_OK) {
                throw new IabException(r, "Error refreshing inventory (querying prices of items).");
            }
        }
        // if subscriptions are supported, then also query for subscriptions
        if (mSubscriptionsSupported) {
            r = queryPurchases(inv, ITEM_TYPE_SUBS);
            if (r != BILLING_RESPONSE_RESULT_OK) {
                throw new IabException(r, "Error refreshing inventory (querying owned subscriptions).");
            }
            if (querySkuDetails) {
                r = querySkuDetails(ITEM_TYPE_SUBS, inv, moreItemSkus);
                if (r != BILLING_RESPONSE_RESULT_OK) {
                    throw new IabException(r, "Error refreshing inventory (querying prices of subscriptions).");
                }
            }
        }
        return inv;
    } catch (RemoteException e) {
        throw new IabException(IABHELPER_REMOTE_EXCEPTION, "Remote exception while refreshing inventory.", e);
    } catch (JSONException e) {
        throw new IabException(IABHELPER_BAD_RESPONSE, "Error parsing JSON response while refreshing inventory.", e);
    }
}
Also used : JSONException(org.json.JSONException) IabException(com.onesignal.example.iap.IabException) RemoteException(android.os.RemoteException) Inventory(com.onesignal.example.iap.Inventory)

Aggregations

IabException (com.onesignal.example.iap.IabException)2 Inventory (com.onesignal.example.iap.Inventory)2 Handler (android.os.Handler)1 RemoteException (android.os.RemoteException)1 IabResult (com.onesignal.example.iap.IabResult)1 JSONException (org.json.JSONException)1