question

Loyal Loops avatar image
Loyal Loops asked ·

Android SDK fails to fetch large number of items from the Inventory

We are using InventoryConnectorfrom the SDK to get inventory items. Calling getItems() should return all items in the inventory.

But this happened to couple of our customers, who have few hundred items it their inventory:

Non-fatal Exception: android.os.TransactionTooLargeException
   at android.os.BinderProxy.transact(Binder.java)
   at com.clover.sdk.v3.inventory.IInventoryService$Stub$Proxy.getItems(IInventoryService.java:1652)
   at com.clover.sdk.v3.inventory.InventoryConnector$1.call(InventoryConnector.java:53)
   at com.clover.sdk.v3.inventory.InventoryConnector$1.call(InventoryConnector.java:51)
   at com.clover.sdk.v1.ServiceConnector.execute(ServiceConnector.java:208)
   at com.clover.sdk.v3.inventory.InventoryConnector.getItems(InventoryConnector.java:51)
   at com.loyalloops.clover.cloverapp.fragments.ProgramListFragment$GetInventoryTask.doInBackground(ProgramListFragment.java:455)
   at com.loyalloops.clover.cloverapp.fragments.ProgramListFragment$GetInventoryTask.doInBackground(ProgramListFragment.java:433)
   at android.os.AsyncTask$2.call(AsyncTask.java:288)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
   at java.lang.Thread.run(Thread.java:841)

We switched to calling API manually to avoid this, but my question here is - why is SDK failing with such a basic task?

I see no customization options for the InventoryConnector.getItems() request, to increase the limit or set an offset, like you can in the API request. This happens for us with the inventory, but I can see how CustomerConnectorwill have the same issue, as number of customers can go up to several thousand.

Inventory
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sam avatar image
sam answered ·
new AsyncTask<Void, Void, Void>(){
                
@Overrideprotected Void doInBackground(Void... params) {
Cursor c = getContentResolver().query(InventoryContract.Item.contentUriWithAccount(CloverAccount.getAccount(mContext)), null, null, null, "_id LIMIT 100 OFFSET 10");
int mNameIndex = c.getColumnIndex("name");
int mUuid = c.getColumnIndex("uuid");
if(c.moveToFirst() && c.getCount() > 0) {
for(String col: c.getColumnNames()) {
Log.i("COLUMNS", col);
}
do {
Log.i("name", c.getString(mNameIndex));
Log.i("uuid", c.getString(mUuid));
} while(c.moveToNext());
}
return null;
}
}.execute();
1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Will try this method and let you know.

0 Likes 0 ·
Jeffrey Blattman avatar image
Jeffrey Blattman answered ·

You can query the inventory DB directly providing whatever SQL limits or filters you wish. E.g.,

Cursor c = getContentResolver().query(InventoryContract.Item.contentUriWithAccount(CloverAccount.getAccount(context)), null, null, null, "limit 100 offset 10");
3 comments
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

You mean InventoryContract.AUTHORITY_URI? Because CONTENT_URI does not exist.

And when I try with AUTHORITY_URI, I get an exception: unknown merchant account: must provide valid token or account.

How do I authenticate these DB queries? I see nothing about this in the documentation.

0 Likes 0 ·

Nvm, I got it. For anyone else looking, its InventoryContract.Item.contentUriWithAccount(CloverAccount.getAccount(context)).

0 Likes 0 ·

Hi @Loyal Loops,
I'm getting the same error of TransactionTooLargeException.I read the above the answer but i don't understand where should i enter this line of code and how to get value from the cursor.Can you please elaborate it and give me some code snippet so that i can solve this problem.I'm stuck a this point.
Please help.Thanks in advance.

0 Likes 0 ·

Welcome to the
Clover Developer Community