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

后端 未结 11 2137
野趣味
野趣味 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:34

    If all above fail to help you, give it a go to try to analyse your code a little - is your IabHelper really set up at the time you're calling it?

    I found myself doing it slightly wrong without realising it. A simple example of using it wrong in Activity.onCreate()

    m_iabHelper = new IabHelper(this, base64EncodedPublicKey); // Declare
    
    m_iabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { // Setup
        public void onIabSetupFinished(IabResult result) {
            // Setup code
        }
    }
    
    // Don't do this, will produce an error
    List additionalSkuList = new ArrayList(); 
    additionalSkuList.add(SKU_MYSKU);
    m_iabHelper.queryInventoryAsync(true, additionalSkuList, m_queryFinishedListener);
    // Don't do this, will produce an error
    

    .

    Above will honour you with the "IAB helper is not set up" error since while your app tries to execute the m_iabHelper.queryInventoryAsync(), the IabHelper it is not set up yet. Consider using these functions in onIabSetupFinished() or somewhere after that function is called (eg. outside the onCreate())

提交回复
热议问题