简体   繁体   中英

In-App Billing query inventory returns SOME (not all) items

I have created 5 items (products) in my developer console but when using QueryInventory to get the SkuDetails of the items, it only returns 4 of them, so I get a Null Pointer Exception when trying to get the details of the not-fetched product.

Also, sometimes it only returns one of the items, and sometimes it doesn't return any of them.

Is it possible that sometimes Google just returns some (and not all) of the products?

I hope someone can help me figure out why:

In this run I didn't get item4

Inside mHelper.startSetup

additionalSkuList.add(SKU_item1); 
additionalSkuList.add(SKU_item2);
additionalSkuList.add(SKU_item3);
additionalSkuList.add(SKU_item4); // this one is missing in the response
additionalSkuList.add(SKU_item5);

mHelper.queryInventoryAsync(true, additionalSkuList,mQueryFinishedListener);

In the queryInventoryListener:

   String item1Price =inventory.getSkuDetails(SKU_item1).getPrice();
   String item2Price =inventory.getSkuDetails(SKU_item2).getPrice();
   String item3Price =inventory.getSkuDetails(SKU_item3).getPrice();
   String item4Price =inventory.getSkuDetails(SKU_item4).getPrice(); //Null Pointer Exc. HERE
   String item5Price =inventory.getSkuDetails(SKU_item5).getPrice();

And all five of the items appear as active in the Google Play Developers Console.

Here is the Logcat output

05-19 19:33:49.048: D/BillingTest(23534): Starting IAB setup.
05-19 19:33:49.048: D/IabHelper(23534): Starting in-app billing setup.
05-19 19:33:49.058: D/IabHelper(23534): Billing service connected.
05-19 19:33:49.058: D/IabHelper(23534): Checking for in-app billing 3 support.
05-19 19:33:49.068: D/IabHelper(23534): In-app billing version 3 supported for com.billingtest.billingtest2
05-19 19:33:49.068: D/IabHelper(23534): Subscriptions AVAILABLE.
05-19 19:33:49.068: I/BillingTest(23534): IAB Setup finished.
05-19 19:33:49.068: I/BillingTest(23534): Setup successful. Querying inventory.
05-19 19:33:49.068: I/BillingTest(23534): Starting to query
05-19 19:33:49.068: D/IabHelper(23534): Starting async operation: refresh inventory
05-19 19:33:49.068: D/IabHelper(23534): Querying owned items, item type: inapp
05-19 19:33:49.068: D/IabHelper(23534): Package name: com.billingtest.billingtest2
05-19 19:33:49.068: D/IabHelper(23534): Calling getPurchases with continuation token: null
05-19 19:33:49.078: D/IabHelper(23534): Owned items response: 0
05-19 19:33:49.078: D/IabHelper(23534): Continuation token: null
05-19 19:33:49.078: D/IabHelper(23534): Querying SKU details.
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item1
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item2
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item3
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item4
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item5
05-19 19:19:23.755: D/IabHelper(21969): Got sku details: SkuDetails:{"title":"item1 (BillingTest)","price":"£0.59","type":"inapp","description":"item1desc","price_amount_micros":990000,"price_currency_code":"USD","productId":"item1"}
05-19 19:19:23.755: D/IabHelper(21969): Got sku details: SkuDetails:{"title":"item2(BillingTest)","price":"£0.59","type":"inapp","description":"item2desc","price_amount_micros":990000,"price_currency_code":"USD","productId":"item2"}
05-19 19:19:23.765: D/IabHelper(21969): Got sku details: SkuDetails:{"title":"item3(BillingTest)","price":"£0.59","type":"inapp","description":"item3desc","price_amount_micros":990000,"price_currency_code":"USD","productId":"item3"}
05-19 19:19:23.765: D/IabHelper(21969): Got sku details: SkuDetails:{"title":"item5(BillingTest)","price":"£1.78","type":"inapp","description":"item5desc","price_amount_micros":2990000,"price_currency_code":"USD","productId":"item5"}
05-19 19:19:23.765: D/IabHelper(21969): Querying owned items, item type: subs
05-19 19:19:23.765: D/IabHelper(21969): Package name: com.billingtest.billingtest2
05-19 19:19:23.765: D/IabHelper(21969): Calling getPurchases with continuation token: null
05-19 19:19:23.775: D/IabHelper(21969): Owned items response: 0
05-19 19:19:23.775: D/IabHelper(21969): Continuation token: null
05-19 19:19:23.775: D/IabHelper(21969): Querying SKU details.
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item1
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item2
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item3
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item4
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item5
05-19 19:19:23.785: D/OpenGLRenderer(21969): Enabling debug mode 0
05-19 19:19:23.805: D/IabHelper(21969): Ending async operation: refresh inventory
05-19 19:19:23.885: I/BillingTest(21969): Inside QueryInventoryFinished Listener
05-19 19:19:23.885: D/BillingTest(21969): Query inventory was successful.
05-19 19:19:23.885: D/AndroidRuntime(21969): Shutting down VM
05-19 19:19:23.885: W/dalvikvm(21969): threadid=1: thread exiting with uncaught exception (group=0x415e9ba8)
05-19 19:19:23.885: E/AndroidRuntime(21969): FATAL EXCEPTION: main
05-19 19:19:23.885: E/AndroidRuntime(21969): Process: com.billingtest.billingtest2, PID: 21969
05-19 19:19:23.885: E/AndroidRuntime(21969): java.lang.NullPointerException
05-19 19:19:23.885: E/AndroidRuntime(21969):    at com.billingtest.billingtest2.MainActivity$1.onQueryInventoryFinished(MainActivity.java:250)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at com.billingtest.billingtest2.util.IabHelper$2$1.run(IabHelper.java:633)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at android.os.Handler.handleCallback(Handler.java:733)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at android.os.Handler.dispatchMessage(Handler.java:95)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at android.os.Looper.loop(Looper.java:136)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at java.lang.reflect.Method.invokeNative(Native Method)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at java.lang.reflect.Method.invoke(Method.java:515)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 19:19:23.885: E/AndroidRuntime(21969):    at dalvik.system.NativeStart.main(Native Method)

Any time you add a new item to your list of In-app Products it usually takes anywhere from 15 minutes to 3 hours to fully propagate to all of the Google Play servers. Same goes for publishing your app or an updated APK. Unfortunately you'll just need to be patient and give the servers time to process your request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM