android 应用内购买 API 3 消费测试购买
android In-App Purchase API 3 consuming test purchase
我在 app.Currently 中使用 API 3 作为应用内功能进行测试 我正在使用测试项目代码
android.test.purchased
一切正常 我可以购买 product.But 如果我再次点击 "Purchase" 按钮,它显示 "already purchased" 并且需要 30 分钟让用户购买 again.Then 我尝试使用以下代码消费此产品,但它最终在 QueryInventoryFinishedListener's
内 if(result.isFailure) condition.Following 是我消费
的代码
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");
}
}
};
我调用此方法来消耗物品,此外我正在使用 google 的 Trivial Drive
示例项目来调用
我得到了解决方案,谢谢 you.I 需要从 Trivial drive Project 编辑 security.java 文件。我将 verifyPurchase 方法中的 "return false" 行更改为 "return true"(不要忘记它只用于调试模式)。现在我可以在应用程序中成功消费测试。以下是验证购买方法的编辑
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);
}
我在 app.Currently 中使用 API 3 作为应用内功能进行测试 我正在使用测试项目代码
android.test.purchased
一切正常 我可以购买 product.But 如果我再次点击 "Purchase" 按钮,它显示 "already purchased" 并且需要 30 分钟让用户购买 again.Then 我尝试使用以下代码消费此产品,但它最终在 QueryInventoryFinishedListener's
内 if(result.isFailure) condition.Following 是我消费
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");
}
}
};
我调用此方法来消耗物品,此外我正在使用 google 的 Trivial Drive
示例项目来调用
我得到了解决方案,谢谢 you.I 需要从 Trivial drive Project 编辑 security.java 文件。我将 verifyPurchase 方法中的 "return false" 行更改为 "return true"(不要忘记它只用于调试模式)。现在我可以在应用程序中成功消费测试。以下是验证购买方法的编辑
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);
}