在没有网络连接的App Billing中

时间:2015-01-15 21:17:06

标签: android in-app-purchase in-app-billing

应用内购买已在我的应用中运行。

重新启动手机:启动我的应用:工作正常(我得到了#34;好东西"我的购买)

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是ownes:my_SKU

但好的东西不是没有互联网连接。

我的问题:

这是正常的吗?我应该在用户已经购买该物品的手机上保存一些数据吗?或者有一种方法,这个Iab API将告诉我用户已经购买它。 (我认为这是一种更安全的方式)

1 个答案:

答案 0 :(得分:2)

是的,这是正常的。建议您每次获得成功时都要保持一定的时间。有了这段时间,你可以决定天气,让你的用户在一定时间内使用该应用程序。例如,允许用户在没有成功回拨一天或2天的情况下使用该应用程序。

当用户没有互联网时,您检查上次成功检查的时间以及是否在您定义的允许时间内,让他们通过。如果没有,则通知用户他们需要再次使用互联网连接