我正在做一个项目,我需要把它变成消耗品。
点击购买按钮,使用以下代码进行消费。
inventory=new Inventory();
mHelper.consumeAsync(inventory.getPurchase(SKU_SUCCESS),mConsumeFinishedListener1);
但它在 IabHelper 类中得到了“购买的空指针异常”。
void consume(Purchase itemInfo) throws IabException {
checkSetupDone("consume");
if (!itemInfo.mItemType.equals(ITEM_TYPE_INAPP)) {
throw new IabException(IABHELPER_INVALID_CONSUMPTION,
"Items of type '" + itemInfo.mItemType
+ "' can't be consumed.");
}
try {
String token = itemInfo.getToken();
String sku = itemInfo.getSku();
if (token == null || token.equals("")) {
logError("Can't consume " + sku + ". No token.");
throw new IabException(IABHELPER_MISSING_TOKEN,
"PurchaseInfo is missing token for sku: " + sku + " "
+ itemInfo);
}
如果有人对此有想法,请告诉我。
consumeAsync() 的代码
public void consumeAsync(Purchase purchase, OnConsumeFinishedListener listener) {
checkSetupDone("consume");
List<Purchase> purchases = new ArrayList<Purchase>();
purchases.add(purchase);
consumeAsyncInternal(purchases, listener, null);
}
public void consumeAsync(List<Purchase> purchases, OnConsumeMultiFinishedListener listener) {
checkSetupDone("consume");
consumeAsyncInternal(purchases, null, listener);
}