question

lucdowell avatar image
lucdowell asked

Cannot find inventory names

Hey guys, I've just started working with clover android SDK, and I've just finished setting up my environment. I'm now trying to run the inventory list display code found at the bottom of this page: https://docs.clover.com/clover-platform/docs/integrate-with-clover-android-sdk


I had issues initially with CloverAccount.getAccount(this) which I fixed by lowering my target SDK, but now I'm having an issue with mInventoryConnector.getItems(). I am not able to get that list for some reason. I added some logs to my code:


public class MainActivity extends AppCompatActivity {

    private Account mAccount;
    private InventoryConnector mInventoryConnector;
    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d("myTag", "Creating");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        super.onResume();

        mTextView = (TextView) findViewById(R.id.activity_main_text_view);
        Log.d("myTag", "onResume");
        // Retrieve the Clover account
        if (mAccount == null) {
            Log.d("myTag", "Could not find account");
            mAccount = CloverAccount.getAccount(this);

            if (mAccount == null) {
                Log.d("myTag", "Couldn't find account, Exiting");
                return;
            }
        }

        // Connect InventoryConnector
        connect();

        // Get Item
        new InventoryAsyncTask().execute();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        disconnect();
    }

    private void connect() {
        disconnect();
        Log.d("myTag", "connecting");
        if (mAccount != null) {
            Log.d("myTag", mAccount.name);
            Log.d("myTag", "Connected");
            mInventoryConnector = new InventoryConnector(this, mAccount, null);
            mInventoryConnector.connect();
        }
    }

    private void disconnect() {
        if (mInventoryConnector != null) {
            mInventoryConnector.disconnect();
            mInventoryConnector = null;
        }
    }

    private class InventoryAsyncTask extends AsyncTask<Void, Void, Item> {

        @Override
        protected final Item doInBackground(Void... params) {
            try {
                //Get inventory item
                Log.d("myTag", "Getting name");
                int sizeOfInventory = mInventoryConnector.getItems().size();
                Log.d("myTag", Integer.toString(sizeOfInventory));
                return mInventoryConnector.getItems().get(0);


            } catch (RemoteException | ClientException | ServiceException | BindingException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected final void onPostExecute(Item item) {
            if (item != null) {
                mTextView.setText(item.getName());
                Log.d("myTag", item.getName());
            } else {
                Log.d("myTag", "Did not find item");
            }
        }
    }
}

Here is my log output:

2020-05-23 20:02:06.465 6739-6739/? D/myTag: onResume
2020-05-23 20:02:06.465 6739-6739/? D/myTag: Could not find account
2020-05-23 20:02:06.467 6739-6739/? D/myTag: connecting
2020-05-23 20:02:06.467 6739-6739/? D/myTag: Test | testcloverdev@gmail.com (DEV)
2020-05-23 20:02:06.467 6739-6739/? D/myTag: Connected
2020-05-23 20:02:06.472 6739-6763/? D/myTag: Getting name
2020-05-23 20:02:06.640 6739-6739/? D/myTag: Did not find item

I'm logging "getting name" before the mInventoryConnector call, and trying to log the size of the list right afterwards to see if it's working, but the .getItems() function is giving me an error.

Any help is appreciated! Thank you!

clover developer communityInventory
10 |2000

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

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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

Welcome to the
Clover Developer Community