Reputation: 1954
Going through the v3 example file in modifying it with my project works fine. However my friend just tested the code by turning wi-fi off and turning on airplane mode. This seems to result in not being able to query the in-app inventory.
// Listener that's called when we finish querying the items and subscriptions we own
private final IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure()) {
// STOPS here and doesn't continue on with no network connection
return;
}
......
}
};
I thought that after a initial successful purchase that v3 stores that locally in it's cache so that it didn't always have to have a network connection to check. Has anyone else ran into this issue? I hope I'm missing something completely obvious or if this is how it's supposed to work.
Upvotes: 12
Views: 7503
Reputation: 193
I solved the problem that away:
final ArrayList<String> iabItemSkus = new ArrayList<String>();
iabItemSkus.add(MyGame.productID_FULLVERSION);
// Disable SKU details if no network connection
boolean checkSkuDetails = isWifiConnected() ? true : false;
Gdx.app.log("IAB", "checkSkuDetails : " + checkSkuDetails);
mHelper.queryInventoryAsync(checkSkuDetails, iabItemSkus, mGotInventoryListener);
Not get Sku details if not network.
Upvotes: 1
Reputation: 315
Problem is, that in your first approach, the API do not know what SKUs exist and per default (the single param version) is trying to query that list. In airplane mode this is not possible - either because it does not cache a list of skus or there is some internal error preventing it from finishing.
You can either send in a list of SKUs you want to query (like you did later on) or you can just supress the online query for sku list.
helper.queryInventoryAsync(false, yourListener);
credits to: jmrmb80
It depends more likely if you need this information (i.e. displaying prices in your app).
(see the other overloads for that function or already given answers. Most likely you don't need the SKUs for checking if a purchase was made I think, so I would go for the answer of jmrmb80 - for me this solved the problem of not recognizing a purchase in airplane mode
Upvotes: 2
Reputation: 2117
For me the following bit worked ...
mHelper.queryInventoryAsync(false, mGotInventoryListener);
instead of
mHelper.queryInventoryAsync(mGotInventoryListener);
I found it in another link a Error refreshing iventory (querying prices of items). (response: 6:Error)
Upvotes: 1
Reputation: 1954
I think I may have found the answer. In following v3's TrivialDriveExample I was calling the queryInventoryAsync function in the mHelper.startSetup() function like so:
Log.d(TAG, "Setup successful. Querying inventory.");
mHelper.queryInventoryAsync(mGotInventoryListener);
Instead now I'm passing a String array list of my SKUs that I want to query for:
List<String> skulist = new ArrayList<String>();
skulist.add("my_sku_name1");
skulist.add("my_sku_name2");
mHelper.queryInventoryAsync(true, skulist, mGotInventoryListener);
I then tested by turning on flight mode and I was able to query my purchases fine!
Upvotes: 8