Android inventory.getSkuDetails() returning null

早过忘川 提交于 2019-11-28 20:08:45

问题


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


      }

   }
}; 

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/23914789/android-inventory-getskudetails-returning-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!