简体   繁体   English

购买易耗品的应用内结算问题

[英]in-app billing issue with purchase of consumable

I have several apps that sell subscriptions but now I'm selling a consumable and it's not quite working right. 我有一些出售订阅的应用程序,但是现在我正在销售消耗品,并且它的工作方式不太正确。 I sell the consumable and the order does indeed go through but my code to immediately consume and provision is not working. 我出售了易损件,订单确实得到了处理,但是我立即使用和供应的代码无法正常工作。 . .

public void btnTranslations_Clicked(View v)
{
    String payload = "";
    DebugLog.debugLog("Launching translations purchase flow", false);
    mHelper.launchPurchaseFlow(this, SKU_TRANSLATIONS, RC_REQUEST,
            mPurchaseFinishedListener, payload);
}
    // Callback for when a purchase is finished
    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
            DebugLog.debugLog("In Purchase finished: " + result + ", purchase: " + purchase, false);

in the above example the purchase flow is successfully launched but control never returns to the PurchaseFinishedListener CallBack. 在上面的示例中,购买流程已成功启动,但是控件从不返回到PurchaseFinishedListener回调。 I know because that debug statement never executes. 我知道,因为该调试语句永远不会执行。

Fortunately, when the app is started up again, the following code 幸运的是,当应用再次启动时,以下代码

mHelper.queryInventoryAsync(mGotInventoryListener); 

is working just fine because the callback works and the consumables the user purchased on the last execution gets consumed and provisioned. 之所以能正常工作,是因为回调有效并且上次执行时用户购买的消耗品被消耗和供应。

So the question is why is the IabHelper.OnIabPLurchaseFinishedListener never getting executed? 所以问题是为什么IabHelper.OnIabPLurchaseFinishedListener永远不会执行? Thanks, Dean 谢谢院长

Well, here I am again answering my own question. 好吧,我在这里再次回答自己的问题。 I don't know if my questions are getting harder or this forum is becoming less useful than it used to be. 我不知道我的问题是否变得越来越难,或者这个论坛变得比以前有用。

The problem was errors and omissions in Google documentation namely this . 问题是Google文档中的错误和遗漏this

The documentation completely fails to say that the following method is required to make immediate consumption and provisioning work . 该文档完全没有说要立即使用和配置工作需要以下方法。 . .

   @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
        if (mHelper == null) return;

        // Pass on the activity result to the helper for handling
        if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
            // not handled, so handle it ourselves (here's where you'd
            // perform any handling of activity results not related to in-app
            // billing...
            super.onActivityResult(requestCode, resultCode, data);
        }
        else {
            Log.d(TAG, "onActivityResult handled by IABUtil.");
        }
    }

The call to mHelper.handleActivityResult somehow causes the mPurchaseFinishedListener callback to execute. 对mHelper.handleActivityResult的调用以某种方式导致执行mPurchaseFinishedListener回调。 The TrivialDrive example code has this method - they just didn't see fit to put it in the how-to instructions. TrivialDrive示例代码具有此方法-他们只是认为不适合将其放入操作说明中。 There are also other errors such as how to properly include the aidl file. 还有其他错误,例如如何正确包含辅助文件。

The harm is that these sloppy docs turn a few-hour task into a few-day task because every one of their omissions/errors takes researching. 有害的是,这些草率的文档将几个小时的任务变成了几天的任务,因为他们的每个遗漏/错误都需要进行研究。

Maybe the next victim of these docs will trip across this post and save some time. 也许这些文档的下一个受害者会跳过这篇文章,并节省一些时间。 Dean 院长

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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