πŸ€–
Android
  • Chat SDK Android
  • Getting Started
    • Chat SDK Quickstart
    • Add the Chat SDK to a Firebase app
    • Add the Chat SDK to a non-Firebase app
  • Setup
    • Add Chat SDK to your project
    • Firebase Setup
    • Chat SDK Initialization
    • Set the Chat SDK Theme
    • Enable Location Messages
    • Authentication Screen
    • Add Additional Modules
    • Module Configuration
    • Proguard
  • API
    • Overriding Activities and Fragments
    • Events
    • Theming
    • Customizing the Icons
    • Tab Customization
    • Add a Chat Option
    • Message Customization
    • Integrating Chat SDK User profiles with your app
    • Overriding the Push Notification Handler
    • Handling Structured Meta Data
  • Chat SDK v4
    • Development Guide
    • Updating from v4 to v5
Powered by GitBook
On this page

Was this helpful?

  1. API

Handling Structured Meta Data

In Android, the ORM we use (GreenDAO) can’t store arrays or maps. It can only store key, value pairs. The ORM we use for iOS (CoreData) on the other hand can store maps and dictionaries. That means that to store structured data for Android we need to take another approach.

Imagine the following data that we want to add to a message's meta payload:

{
    key1: {
        sub1: β€œa”,
        sub2: β€œb”
    },
    key2: β€œc"
}

To store this in Android we would need to do the following:

message.setValueForKey(β€œa", "key1/sub1”);
message.setValueForKey(β€œb", "key1/sub2");
message.setValueForKey(β€œc", "key2");

You can also use the HashMapHelper class to convert between these two representations:

Map<String, String> sub = new HashMap<String, String>() {{
            put("sub1", "a");
            put("sub2", "b");
        }};
Map<String, Object> map = new HashMap<String, Object>() {{
    put("key1", sub);
    put("key2", "c");
}};

You can then flatten the map:

Map<String, Object> flat = HashMapHelper.flatten(map);

This yields:

{
  key2=c, 
  key1/sub2=b, 
  key1/sub1=a
}

You can also expand the map:

Map<String, Object> expanded = HashMapHelper.expand(flat);

Which yields:

{
  key2=c, 
  key1={
    sub1=a, 
    sub2=b
  }
}
PreviousOverriding the Push Notification HandlerNextDevelopment Guide

Last updated 3 years ago

Was this helpful?