Android In-App Billing v3: “Can't perform operation: queryInventory”

后端 未结 11 2145
野趣味
野趣味 2021-01-31 09:15

I have setup In-App Billing for the first time using the new v3 API. It is working correctly on my devices but I have received a lot of error reports from other users.

O

11条回答
  •  广开言路
    2021-01-31 09:39

    As @Martin explained, there was a bug in the Google In-App Billing example which caused this.

    However, after fixing it, I was still receiving some errors in internal calls (queryInventory inside the thread created in queryInventoryAsync in some rare cases reports that the helper is not setup). I have solved this by adding an additional catch in that case:

    try {
        inv = queryInventory(querySkuDetails, moreSkus);
    }
    catch (IabException ex) {
        result = ex.getResult();
    }
    catch(IllegalStateException ex){ //ADDED THIS CATCH
        result = new IabResult(BILLING_RESPONSE_RESULT_ERROR, "Helper is not setup.");
    }
    

    I also got a crash on mHelper.dispose() which I fixed in a similar way:

    try{
        if (mContext != null) mContext.unbindService(mServiceConn);
    }
    catch(IllegalArgumentException ex){ //ADDED THIS CATCH
        //IGNORE IT - somehow, the service was already unregistered
    }
    

    Of course, instead of ignoring these errors you can silently log them to ACRA, for example :)

    Thanks for all your comments.

提交回复
热议问题