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.
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.