0

I'm using SendBird chat API in my Android App, and I'm having issue when getting more than 1 value in metadata.

That's the groupchannel metadata creation:

final HashMap<String, String> data = new HashMap<String, String>();
        data.put("owner", "Daniel");
        data.put("address", "Else Street");

     groupChannel.createMetaData(data, new BaseChannel.MetaDataHandler() {
                            @Override
                            public void onResult(Map<String, String> map, SendBirdException e) {
                                if(e != null) {
                                    Toast.makeText(ctx, "" + e.getCode() + ":" + e.getMessage(), Toast.LENGTH_SHORT).show();
                                    return;
                                }

If I iterate the map at onResult, I will get "Daniel" and "Else Street". So far soo good, right?

The problem is now when I need to get metadata:

List<String> keys = new ArrayList<String>();

                    keys.add("owner");
                    keys.add("address");
 mGroupChannel.getMetaData(keys, new BaseChannel.MetaDataHandler() {
                        @Override
                        public void onResult(Map<String, String> map, SendBirdException e) {
                            if (e != null) {
                                Toast.makeText(ChatActivity.this, "" + e.getCode() + ":" + e.getMessage(), Toast.LENGTH_SHORT).show();
                                return;
                            }
                            Toast.makeText(getBaseContext(), String.valueOf(map.size()), Toast.LENGTH_LONG).show();
                        }
                    });

map.size() methos is returning 0 when it should actually returns 2. The problem is that, if I remove address or owner, it returns 1, which is correct.

1 Answers1

0

There was a similar problem at 3.0.0 but it is fixed now.

And regarding your pasted code, it should look like this.

mGroupChannel.createMetaData(data, new BaseChannel.MetaDataHandler() {
    @Override
    public void onResult(Map<String, String> map, SendBirdException e) {
        // Toast.makeText(getContext(), String.valueOf(map.size()), Toast.LENGTH_LONG).show();

        List<String> keys = new ArrayList<String>();

        keys.add("address");
        keys.add("owner");

        mGroupChannel.getMetaData(keys, new BaseChannel.MetaDataHandler() {
            @Override
            public void onResult(Map<String, String> map, SendBirdException e) {
                Toast.makeText(getContext(), String.valueOf(map.size()), Toast.LENGTH_LONG).show();
            }
        });
    }
});

Or anything that makes sure to call getMetaData after createMetaData is finished will be fine.

Jay Yun
  • 31
  • 3
  • Hey bro, I updated to 3.0.2 in my build.gradle tried again and still doesn't work and I'm doing the EXACTLY SAME THING AS IT IS in the documentation. Can you please help me? ): – Daniel Gomes Sep 17 '16 at 13:11
  • Do you call getMetaData after createMetaData is finalized by calling its callback handler? – Jay Yun Sep 17 '16 at 14:51
  • Can you take a look at the code? Go to initGroupChannel() method http://pastebin.com/SED3Qydp – Daniel Gomes Sep 17 '16 at 15:07
  • I tried in a sample app and it worked fine, but in my real app it's not loading dialogs list.. it says: error: 400401 Api token missing – Daniel Gomes Sep 18 '16 at 22:29