首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android IAB V3消费购买

Android IAB V3消费购买
EN

Stack Overflow用户
提问于 2013-06-01 15:22:32
回答 1查看 3.4K关注 0票数 0

我已经在我的安卓游戏中实现了应用内计费v3,但在尝试消费时遇到了问题。

游戏已发布,产品可以成功购买,但是由于消费者失败,因此只能购买一次。当第二次尝试购买时,返回响应5 - developer error

有人能给我一些建议吗?

这是我的代码:

代码语言:javascript
复制
        public boolean orderBoostersV3(String packId, int alreadyAfterConsume) {
            Bundle bundle = null;
            try {
    // for tetsing               packId = "android.test.purchased";
                if (mService == null) {
                    Log.e(TAG, "mService is null");
                    return false;
                }
                // Bundle ownedItems = mService.getPurchases(3, "eu.acgame", "inapp", null);


                bundle = mService.getBuyIntent(3, "eu.acgame", packId, ITEM_TYPE_INAPP, "AC game");

                PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
                if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
                    // Start purchase flow (this brings up the Google Play UI).
                    // Result will be delivered through onActivityResult().
                    try {
                        a.startIntentSenderForResult(pendingIntent.getIntentSender(), RC_BUY, new Intent(),
                                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
                        // consume(packId); // consuming right after prdering does not work
                        return true;
                    } catch (IntentSender.SendIntentException e) {
                        Log.e(TAG, "Billing unavailable. Error:" + e.getMessage());
                        e.printStackTrace();
                    }
                } else if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE) {
                    Log.d(TAG, "Boostering not available");
                    return false;
                } else if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED && alreadyAfterConsume > 10) {
                    Log.e(TAG, "Consume did not work " + alreadyAfterConsume + " Panic!");
                    return false;
                } else if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                    Log.d(TAG, "Product " + packId + " already purchased. Calling consume");
                    int result = consume(packId);   // if result not 0, probably all consumed
                    if (result == 0 || result == 5)   // consumed properly, try once more
                        return orderBoostersV3(packId, alreadyAfterConsume + 1);
                    else
                        return orderBoostersV3(packId, 99);  // finish consuming

                } else
                    Log.d(TAG, "Billing unexpected code:" + bundle.getInt(RESPONSE_CODE));

            } catch (RemoteException e) {
                Log.e(TAG, "Billing error");
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }
            return false;
        }

private int consume(String packId) throws RemoteException {
    Bundle purchases = mService.getPurchases(3, "eu.acgame", "inapp", null);
    Log.d(TAG, "Purchases:" + purchases);
    int response = mService.consumePurchase(3, "eu.acgame", "inapp:eu.acgame:" + packId); // android.test.purchased");
    Log.d(TAG, "Consume response:" + response);
    return response;
}
EN

回答 1

Stack Overflow用户

发布于 2013-06-02 17:18:06

我已经设法解决了我自己的问题。我必须将原始的购买令牌传递给consumePurchase,这是从查询购买项目集合中获得的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16870203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档