Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Billing - I receive response code 5

I had my in-app billing working, but then I moved some code around for greater extensibility and it broke. Essentially what I was trying to do was make an Adapter for my addons so that it would be easier to add them in with less programming effort later. My project has billing permissions in the manifest and is configured for billing on the Google Play Store so that's not the issue.

AdOnsActivity

public class AdOnsActivity extends AppCompatActivity {
    private IInAppBillingService mService;
    private ServiceConnection mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ad_ons);

        Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

        listAdOns = findViewById(R.id.listAdOns);

        Handler handler = new Handler();
        handler.post(new Runnable() {
            @Override
            public void run() {
                try {
                    ...
                    listAdOns.setAdapter(new AdOnAdapter(AdOnsActivity.this, json.getJSONArray("adOns"), mService));
                } catch (Exception e) {
                    Toast.makeText(AdOnsActivity.this, getResources().getString(R.string.error_load_ad_ons), Toast.LENGTH_SHORT).show();
                    e.printStackTrace();
                    finish();
                }
            }
        });
    }

AdOnAdapter

public class AdOnAdapter extends BaseAdapter {
    public AdOnAdapter(Activity activity, JSONArray adOns, IInAppBillingService mService) throws RemoteException {
        Bundle querySkus = new Bundle();

        this.activity = activity;
        this.adOns = adOns;
        this.mService = mService;

        skuDetails = mService.getSkuDetails(3, activity.getPackageName(), "inapp", querySkus);
        responseDetails = skuDetails.getInt("RESPONSE_CODE");
        ownedItems = mService.getPurchases(3, activity.getPackageName(), "inapp", null);
        responseOwned = ownedItems.getInt("RESPONSE_CODE");
    }
like image 500
eshimoniak Avatar asked Apr 24 '18 04:04

eshimoniak


1 Answers

All the response codes are listed here.

5 means you are calling the API with invalid arguments. You have broken your API call somehow. Maybe compare the contents of your API call under the old and new version of your code (you are using source control right?).

  • 0. BILLING_RESPONSE_RESULT_OK: Success
  • 1. BILLING_RESPONSE_RESULT_USER_CANCELED: User pressed back or canceled a dialog
  • 2. BILLING_RESPONSE_RESULT_SERVICE_UNAVAILABLE: Network connection is down
  • 3. BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE: Billing API version is not supported for the type requested
  • 4. BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE: Requested product is not available for purchase
  • 5. BILLING_RESPONSE_RESULT_DEVELOPER_ERROR: 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
  • 6. BILLING_RESPONSE_RESULT_ERROR: Fatal error during the API action
  • 7. BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED: Failure to purchase since item is already owned
  • 8. BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED: Failure to consume since item is not owned
like image 140
Nick Fortescue Avatar answered Sep 27 '22 18:09

Nick Fortescue