In-App Billing test: android.test.purchased already owned

后端 未结 16 1398
情深已故
情深已故 2020-12-07 08:09

I am currently testing In-App Billing for a future app, and after I successfully \"bought\" the test item \"android.test.purchased\" the first time, I now receive the respon

16条回答
  •  庸人自扰
    2020-12-07 08:31

    If you are in test environment

    1) In the case of android.test.purchased, I can reset the fake payment by restarting android device(consumed the inventory).

    2) In InApp util there is a file called Security.java make it as following, for temporary. Since the testing payment(fake) always return false due to security exception.

    public static boolean verifyPurchase(String base64PublicKey,
                                         String signedData, String signature) {
        return true; }
    

    Then in your OnIabPurchaseFinishedListener call fechInvForconsumeItem()

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
                = new IabHelper.OnIabPurchaseFinishedListener() {
            public void onIabPurchaseFinished(IabResult result,
                                              Purchase purchase)
            {
                if (result.isFailure()) {
                    // Handle error
                    Log.e("123","Failure");
    
                    return;
                }
                else if (purchase.getSku().equals(ITEM_SKU)) {
                    Log.e("123","PURCAsed");
                    fechInvForconsumeItem(); // Restart device if not consume
    
                }
    
            }
        };
    

    The fechInvForconsumeItem() is

        public void fechInvForconsumeItem() {
        mHelper.queryInventoryAsync(mReceivedInventoryListener);
    }
    IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
            = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result,
                                             Inventory inventory) {
    
    
            if (result.isFailure()) {
                // Handle failure
                Log.e("11","Failure");
    
    
    
            } else {
                Log.e("11","suc");
                mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
                        mConsumeFinishedListener);
            }
    
    
        }
    };
    

    Consume Listener is

        IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
            new IabHelper.OnConsumeFinishedListener() {
                public void onConsumeFinished(Purchase purchase,
                                              IabResult result) {
    
                    if (result.isSuccess()) {
                    } else {
                        // handle error
                        Log.e("11","sucConsume");
                    }
                }
            };
    

提交回复
热议问题