Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

android - In-app billing v3 unable to query items without network connection or in airplane/flight mode

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...