Non-consumable in-app billing test item becomes consumable sometimes - Google Play

571 views Asked by At

I implement an in-app for Google Play. I use the test item: android.test.purchased and described the item as NONconsumable (not consuming it anywhere in the code with mHelper.consumeAsync). While running the app, after some "restart"s and "force close"s, "going online to offline" and "offline to online" somewhere in the middle, the item becomes consumable again and I can purchase the item. It is consumable sometimes and non consumable other times! I appreciate any suggestion. My code is below:

... public class Home extends Activity {

... static final String ITEM_SKU = "android.test.purchased"; IabHelper mHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...

}
@Override
protected void onStart() {
    super.onStart();

    mHelper = new IabHelper(this, key);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener(){
        public void onIabSetupFinished(IabResult result){
            if (!result.isSuccess()){
                Log.d("setup", "NOT OK");
            }
            else{
                Log.d("setup", "OK");
                List SKU_List = new ArrayList();
                SKU_List.add(ITEM_SKU);
                mHelper.queryInventoryAsync(false, SKU_List, mQueryFinishedListener);
            }
        }
    });
}

IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener(){
    @Override
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

        if (result.isFailure()) {

            return;
        }

        try {
            if (inventory.hasPurchase(ITEM_SKU)) {

                buttonsInPremiumMode();

            } else {

                buttonsNOTPremiumMode();
                String itemPrice = inventory.getSkuDetails(ITEM_SKU).getPrice();
                buyPremiumButton.setText(getResources().getString(R.string.buyPremiumButton) + itemPrice);

            }
        }
        catch(Exception e){

        }
    }
};

private void purchase(){
    if (mHelper != null){
        mHelper.flagEndAsync();
        mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001, mPurchaseFinishedListener, "payloadercode");
    }
}

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener(){
    public void onIabPurchaseFinished(IabResult result, Purchase purchase){
        if (result.isFailure()){

        }
        else if (purchase.getSku().equals(ITEM_SKU)){
            buttonsInPremiumMode();
        }
        else {
        }
    }
};

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
@Override
public void onDestroy() {
    super.onDestroy();
    if (mHelper != null) {
        mHelper.dispose();
    }
    mHelper=null;
}
private void buttonsNOTPremiumMode(){
    ...
}

private void buttonsInPremiumMode(){
    ...
}

}

1

There are 1 answers

0
ozo On BEST ANSWER

Putting mHelper.flagEndAsync() just before mHelper.launchPurchaseFlow fixed my problem.