Search code examples
androidin-app-purchasein-app-billing

In App Billing without network connection


The in app purchasing is already working in my app.

Restarting the phone: Launching my app: works fine (I get the "goodies" of my purchase)

This is the LogCat that shows it worked:

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.

After this my if statement was true:

 if (inventory.hasPurchase(MY_SKU)

But, without internet it is not working:

The 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.

This is the part where the if statement was true, so it didn't continue

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;
        }

You can see, that in both case:

It knows Sku is ownes: my_SKU

But the goodies not coming without internet connection.

My question:

Is this the normal working? Should I save some data on the phone that the user already bought the item? Or there is a way where this Iab API will tell me wheter the user has already bought it. (I think that is a more secure way)


Solution

  • yes this is normal. what is recommended is that every time you get a success you keep a time that was checked. With that time you can decide weather to allow your user to use the app for a certain amount of time for not. Ex the user is allowed to use the app without a successful callback for a day or 2.

    when the user does not have internet you check the time your last successful check was and if it is in your defined allowed time, let them pass. if not then notify the user that they need to try again with an internet connection