Question

please, I'm getting crazy about this.

I can make a purchase from one of my testers but I'm not been able to retrieve the price of my product.

See, below is the code to "connect":

    //Binding Service
   bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
                    mServiceConn, Context.BIND_AUTO_CREATE);

    String base64EncodedPublicKey;

    base64EncodedPublicKey = getString(R.string.baseEncodedPubKey);

    // compute your public key and store it in base64EncodedPublicKey
    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.d("TMA Setup Billing", "Problem setting up In-app Billing: " + result);
              }            
                 // Hooray, IAB is fully set up!  
              else{

                  Log.d("TMA Setup Billing", "Ready to sell! OK!! " + result);

                  //Get the prices of inApps
                  Bundle teste = null;
                  ArrayList<String> teste1 = null;

                  getInAppsInfo(teste,teste1);

              }
           }
        });

From the code above, I got the Ok message so it's connecting...

The problem is at this code below:

    //Func syncr to download prices
private synchronized void getInAppsInfo(final Bundle querySkus,final ArrayList<String> skuList) {
    AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {

        @Override
        public String doInBackground(Void... params) {

        ArrayList<String> skuList = new ArrayList<String>(); 
              skuList.add(getString(R.string.prod1_maistempo));  
              Bundle querySkus = new Bundle(); 
              querySkus.putStringArrayList("DETAILS_LIST", skuList);

              String resposta = getString(R.string.naodisp);

              try {
                  Bundle skuDetails = mService.getSkuDetails(3, getPackageName(), "inapp", querySkus);

    int response = skuDetails.getInt("RESPONSE_CODE");
    Log.d("TMA Synch Billing","response = " + response );
    preco = preco + " " + response;
    if (response == 0) {
        Log.d("TMA Synch Billing","response = OK");
        ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
        for (String thisResponse : responseList) {
        JSONObject object = new JSONObject(thisResponse);
        String sku = object.getString("productId");
        String price = object.getString("price");
        Log.d("TMA Synch Billing","Sky e Price: " + sku + " " + price);
        if (sku.equals(getString(R.string.prod1_maistempo))) resposta = price;
               }
            }
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            Log.d("TMA Synch Billing","Error Remote: " + e.getMessage());
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Log.d("TMA Synch Billing","Error JSON: " + e.getMessage());
        }


        return resposta;

        }

        @Override
        protected void onPostExecute(String result) {
            preco = preco + " " + result;
        }

    };
    task.execute();
}

This funcion is returning 5 > (BILLING_RESPONSE_RESULT_DEVELOPER_ERROR 5
Invalid arguments provided to the API. This error can also indicate that the application was not correctly signed or properly set up for In-app Billing in Google Play, or does not have the necessary permissions in its manifest)

But then, I can, with this same device (and is the same to all my testers friends), buy the inApp sucesfully with this code:

    //Yes button clicked, Start buy Activity

                    Bundle buyIntentBundle;
                    try {
                        buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
                               getString(R.string.prod1_maistempo), "inapp", "buyer info");

                        PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

                        startIntentSenderForResult(pendingIntent.getIntentSender(),
                                   1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
                               Integer.valueOf(0));

                    } catch (RemoteException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Log.d("TMA billing Buy "," Remote " + e.getMessage());
                    } catch (SendIntentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Log.d("TMA billing Buy "," SendIntent " + e.getMessage());
                    }

And then, I could handle the JSON string with the examples from google.

So, can you tell me what I'm doing wrong in my function to get the price? Thank you so much guys.

Was it helpful?

Solution

The Bundle you pass into getSkuDetails has a ArrayList<String> with they key ITEM_ID_LIST, not DETAILS_LIST as you have it (DETAILS_LIST is the ArrayList<String> in the response Bundle)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top