简体   繁体   中英

In-App Billing: How to query the inventory after purchase, in order to get the price and currency code?

I am trying to obtain the price and the currency code after I've made a purchase using Google In-App Billing in my Android app.

Right after a successful purchase, I query the inventory for the same SKU but I get null

new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
        if (result.isFailure()) {
            return;
        } else if (purchase.getSku().equals(MY_SKU)) {
            if (purchase.getPurchaseState() == 0) {
                try {
                    Inventory inventory = appBillingHelper.queryInventory();
                    price = inventory.getSkuDetails(MY_SKU).getPrice(); // CRASHES WITH A NULL POINTER EXCEPTION for SkuDetails.
                    currencyCode = inventory.getSkuDetails(MY_SKU).getPriceCurrencyCode();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM