消费者测试购买的Android应用内购买API 3

时间:2015-03-25 11:34:13

标签: android in-app-purchase

我在app中使用API​​ 3 for app功能。目前我正在使用测试项代码

  

android.test.purchased

一切正常我能买到产品。但是如果我点击"购买"按钮再次显示"已经购买"并且需要30分钟让用户再次购买。然后我尝试使用以下代码来使用此产品,但它最终在QueryInventoryFinishedListener's if(result.isFailure)条件内。最后是我的代码消费

public void consumeItem() {
        mHelper.queryInventoryAsync(mReceivedInventoryListener);

    }

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


            if (result.isFailure()) {
                // Handle failure

                Log.i("Ajji", "Failed in Query Inventory Finished Listener");

            } else {
                mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
                        mConsumeFinishedListener);

            }
        }
    };

    IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
        public void onConsumeFinished(Purchase purchase, IabResult result) {

            if (result.isSuccess()) {
                // clickButton.setEnabled(true);

                Log.i("Ajji", "Item Consumed Successfully");
                rowPayment.setClickable(true);

            } else {
                // handle error
                Log.i("Ajji", "Not Consumed");
            }
        }
    };

我将此方法称为消费项目,此外我正在使用谷歌的Trivial Drive示例项目拨打电话

1 个答案:

答案 0 :(得分:1)

我得到了解决方案,谢谢。我需要编辑来自Trivial驱动项目的security.java文件。我改变了#34;返回false"在verifyPurchase方法中输入"返回true" (不要忘记它仅用于调试模式)。现在我可以在app中成功使用测试。以下是Verify Purchase方法的编辑

public static boolean verifyPurchase(String base64PublicKey,
        String signedData, String signature) {
    if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey)
            || TextUtils.isEmpty(signature)) {
        Log.e(TAG, "Purchase verification failed: missing data.");
        if (BuildConfig.DEBUG) {
            return true;
        }
        return false;
    }

    PublicKey key = Security.generatePublicKey(base64PublicKey);
    return Security.verify(key, signedData, signature);
}