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");
}
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?).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With