简体   繁体   中英

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

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(){
    ...
}

}

将mHelper.flagEndAsync()放在mHelper.launchPurchaseFlow之前即可解决我的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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