Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android inventory.getSkuDetails() returning null

Hi i'm trying to add in app purchases to my app i have set up my in app purchases on the developer console which are set to active i have then queried them which yesterday was working perfectly i retrieved all the details but today its coming back as null. the only thing that has changed is that i had to uninstall the app and re-run it. I have checked my skus both in the app and on the developer console which match exactly when i run IabHelper start setup i get a result of ok. And then i call IabHelper.QueryInventoryFinishedListener and that results back as being ok but when i try access anything from the inventory it comes back as null. does anyone know why? or if i'm doing some wrong in my code?

in my on Create();

mHelper = new IabHelper(this, base64EncodedPublicKey);
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
               public void onIabSetupFinished(IabResult result) {
                  if (!result.isSuccess()) {
                     // Oh noes, there was a problem.
                     Log.v("Menu", "Problem setting up In-app Billing: " + result);
                  }            
                     // Hooray, IAB is fully set up!  
                  Log.v("Menu", "INAPP BILLING SETUP COMPLETE: " + result);
                  ArrayList<String> skuList = new ArrayList<String> ();
                    skuList.add("myapp.consumable.inapppurchase_id_1");
                    skuList.add("myapp.consumable.inapppurchase_id_2");
                    skuList.add("myapp.consumable.inapppurchase_id_3");
                    skuList.add("myapp.permanant.inapppurchase_id_6");
                    skuArray = new JSONArray(skuList);

                    mHelper.queryInventoryAsync(true, skuList, mQueryFinishedListener);

               }
        });

Then i heres my code for the QueryListener

IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
       public void onQueryInventoryFinished(IabResult result, Inventory inventory)   
       {
          if (result.isFailure()) {
              Log.v("Menu", "RESULT FALIURE");
             return;
           }

      Log.v("Menu", "this +" + skuArray);
      Log.v("Menu", "Inventory +" + inventory);
      for(int i = 0; i < skuArray.length(); i++){
          try {
             String SKU = skuArray.getString(i);

             if(inventory.getSkuDetails(SKU) != null){
                 Log.v("Menu", "SKU = " + SKU);
                 Log.v("Menu", "SKU" + SKU + "= " + inventory.getSkuDetails(SKU));

                 updateProductData("price",inventory.getSkuDetails(SKU).getPrice(),i);
                 updateProductData("id",inventory.getSkuDetails(SKU).getSku(),i);


             }else{
                 Log.v("Menu", "SKU RETURNED NULL" + SKU); 
             }



        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


      }

   }
}; 
like image 694
Luke Batley Avatar asked May 28 '14 14:05

Luke Batley


2 Answers

Ok i spoke to Google about this issue. And they say they have made changes which requires the apk to be published before adding in app purchases they recommend uploading the apk to alpha testing channel and published (not in draft mode).

Ill give it a try and feed back if it works

like image 178
Luke Batley Avatar answered Dec 17 '22 15:12

Luke Batley


After I published my alpha apk to google play the billing started to work again.

like image 40
Json Avatar answered Dec 17 '22 15:12

Json