这是我第一次在Android应用程序中实现应用程序内计费,我直接从指南中获取了大部分代码,一切都忘记了直到我想到退款.示例应用程序已经实施了退款,但是以一种奇怪的方式!退款是在应用程序上收到的,但退款状态完全可以理解,但原始来源如下:
// Count the number of times the product was purchased
while (cursor.moveToNext()) {
int stateIndex = cursor.getInt(2);
PurchaseState state = PurchaseState.valueOf(stateIndex);
// Note that a refunded purchase is treated as a purchase. Such
// a friendly refund policy is nice for the user.
if (state == PurchaseState.PURCHASED || state == PurchaseState.REFUNDED) {
quantity += 1;
}
}
// Update the "purchased items" table
updatePurchasedItem(productId, quantity);
Run Code Online (Sandbox Code Playgroud)
它的添加项目,即使它被退还,我不知道为什么会这样?退款项目是否有特殊ID或我缺少什么?我只用测试产品试过这个,所以我不知道.
如果数量为0似乎完全正确,则updatePurchasedItem方法从表中删除条目,因此我将代码更改为此
while (cursor.moveToNext()) {
int stateIndex = cursor.getInt(2);
PurchaseState state = …Run Code Online (Sandbox Code Playgroud)