在没有网络连接的应用程序计费中
In App Billing without network connection
应用内购买已在我的应用中运行。
重新启动 phone:启动我的应用程序:工作正常(我得到了我购买的 "goodies")
这是LogCat,表明它有效:
01-15 21:54:42.039 29574-29616/mypackage D/IabHelper﹕ Got sku details: SkuDetails:{"title":"MySKU","price":"X USD","type":"inapp","description":"My description.","price_amount_micros":x,"price_currency_code":"USD","productId":"myID"}
01-15 21:54:42.039 29574-29616/mypackage D/IabHelper﹕ Querying owned items, item type: subs
01-15 21:54:42.039 29574-29616/mypackage D/IabHelper﹕ Package name: mypackage
01-15 21:54:42.039 29574-29616/mypackage D/IabHelper﹕ Calling getPurchases with continuation token: null
01-15 21:54:42.059 29574-29616/mypackage D/IabHelper﹕ Owned items response: 0
01-15 21:54:42.059 29574-29616/mypackage D/IabHelper﹕ Continuation token: null
01-15 21:54:42.069 29574-29616/mypackage D/IabHelper﹕ Querying SKU details.
01-15 21:54:43.209 29574-29616/mypackage D/IabHelper﹕ Ending async operation: refresh inventory
01-15 21:54:43.219 29574-29574/mypackage D/InAppPurchaseManager﹕ Query inventory finished.
01-15 21:54:43.219 29574-29574/mypackage D/InAppPurchaseManager﹕ Query inventory was successful.
在此之后我的 if 语句为真:
if (inventory.hasPurchase(MY_SKU)
但是,如果没有互联网,它是行不通的:
LogCat:
01-15 21:36:55.169 27961-27961/mypackage D/IabHelper﹕ In-app billing version 3 supported for mypackage
01-15 21:36:55.179 27961-27961/mypackage D/IabHelper﹕ Subscriptions AVAILABLE.
01-15 21:38:10.289 27961-27961/mypackage D/IabHelper﹕ Starting async operation: refresh inventory
01-15 21:38:11.809 27961-28082/mypackage D/IabHelper﹕ Querying owned items, item type: inapp
01-15 21:38:11.809 27961-28082/mypackage D/IabHelper﹕ Package name: mypackage
01-15 21:38:11.809 27961-28082/mypackage D/IabHelper﹕ Calling getPurchases with continuation token: null
01-15 21:38:11.829 27961-28082/mypackage D/IabHelper﹕ Owned items response: 0
01-15 21:38:11.869 27961-28082/mypackage D/IabHelper﹕ Sku is owned: my_SKU
01-15 21:38:11.899 27961-28082/mypackage D/IabHelper﹕ Continuation token: null
01-15 21:38:11.899 27961-28082/mypackage D/IabHelper﹕ Querying SKU details.
这是 if 语句为真的部分,所以它没有继续
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// Is it a failure?
if (result.isFailure()) {
return;
}
你可以看到,在这两种情况下:
它知道 Sku 是拥有者:my_SKU
但是没有互联网连接就不会出现好东西。
我的问题:
这是正常工作吗?我是否应该在 phone 上保存用户已购买该商品的一些数据?或者有一种方法可以让这个 Iab API 告诉我用户是否已经购买了它。 (我认为这是一种更安全的方式)
是的,这是正常的。建议的是,每次你获得成功时,你都保留一个被检查的时间。有了那个时间,您可以决定天气,让您的用户在一定时间内不使用该应用程序。例如,允许用户在一天或两天内没有成功回调的情况下使用该应用程序。
当用户没有互联网时,您检查上次成功检查的时间,如果在您定义的允许时间内,则让他们通过。如果没有,则通知用户他们需要使用互联网连接重试
应用内购买已在我的应用中运行。
重新启动 phone:启动我的应用程序:工作正常(我得到了我购买的 "goodies")
这是LogCat,表明它有效:
01-15 21:54:42.039 29574-29616/mypackage D/IabHelper﹕ Got sku details: SkuDetails:{"title":"MySKU","price":"X USD","type":"inapp","description":"My description.","price_amount_micros":x,"price_currency_code":"USD","productId":"myID"}
01-15 21:54:42.039 29574-29616/mypackage D/IabHelper﹕ Querying owned items, item type: subs
01-15 21:54:42.039 29574-29616/mypackage D/IabHelper﹕ Package name: mypackage
01-15 21:54:42.039 29574-29616/mypackage D/IabHelper﹕ Calling getPurchases with continuation token: null
01-15 21:54:42.059 29574-29616/mypackage D/IabHelper﹕ Owned items response: 0
01-15 21:54:42.059 29574-29616/mypackage D/IabHelper﹕ Continuation token: null
01-15 21:54:42.069 29574-29616/mypackage D/IabHelper﹕ Querying SKU details.
01-15 21:54:43.209 29574-29616/mypackage D/IabHelper﹕ Ending async operation: refresh inventory
01-15 21:54:43.219 29574-29574/mypackage D/InAppPurchaseManager﹕ Query inventory finished.
01-15 21:54:43.219 29574-29574/mypackage D/InAppPurchaseManager﹕ Query inventory was successful.
在此之后我的 if 语句为真:
if (inventory.hasPurchase(MY_SKU)
但是,如果没有互联网,它是行不通的:
LogCat:
01-15 21:36:55.169 27961-27961/mypackage D/IabHelper﹕ In-app billing version 3 supported for mypackage
01-15 21:36:55.179 27961-27961/mypackage D/IabHelper﹕ Subscriptions AVAILABLE.
01-15 21:38:10.289 27961-27961/mypackage D/IabHelper﹕ Starting async operation: refresh inventory
01-15 21:38:11.809 27961-28082/mypackage D/IabHelper﹕ Querying owned items, item type: inapp
01-15 21:38:11.809 27961-28082/mypackage D/IabHelper﹕ Package name: mypackage
01-15 21:38:11.809 27961-28082/mypackage D/IabHelper﹕ Calling getPurchases with continuation token: null
01-15 21:38:11.829 27961-28082/mypackage D/IabHelper﹕ Owned items response: 0
01-15 21:38:11.869 27961-28082/mypackage D/IabHelper﹕ Sku is owned: my_SKU
01-15 21:38:11.899 27961-28082/mypackage D/IabHelper﹕ Continuation token: null
01-15 21:38:11.899 27961-28082/mypackage D/IabHelper﹕ Querying SKU details.
这是 if 语句为真的部分,所以它没有继续
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// Is it a failure?
if (result.isFailure()) {
return;
}
你可以看到,在这两种情况下:
它知道 Sku 是拥有者:my_SKU
但是没有互联网连接就不会出现好东西。
我的问题:
这是正常工作吗?我是否应该在 phone 上保存用户已购买该商品的一些数据?或者有一种方法可以让这个 Iab API 告诉我用户是否已经购买了它。 (我认为这是一种更安全的方式)
是的,这是正常的。建议的是,每次你获得成功时,你都保留一个被检查的时间。有了那个时间,您可以决定天气,让您的用户在一定时间内不使用该应用程序。例如,允许用户在一天或两天内没有成功回调的情况下使用该应用程序。
当用户没有互联网时,您检查上次成功检查的时间,如果在您定义的允许时间内,则让他们通过。如果没有,则通知用户他们需要使用互联网连接重试