非消费类应用内结算测试项目有时会变为耗材 - Google Play

时间:2014-11-11 14:31:32

标签: android testing in-app-purchase google-play in-app

我为Google Play实施了一个应用内应用。我使用测试项:android.test.purchased并将该项描述为NONconsumable(不使用mHelper.consumeAsync在代码中的任何地方使用它)。在运行应用程序时,经过一些“重启”和“强制关闭”,“在线离线”和“离线到在线”中间的某个地方,该项目再次成为消耗品,我可以购买该项目。它有时是消耗品,其他时间是非消耗品!我感谢任何建议。我的代码如下:

... public class Home扩展活动{

...     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 个答案:

答案 0 :(得分:0)

把      mHelper.flagEndAsync() 就在此之前      mHelper.launchPurchaseFlow 解决了我的问题。