Initial setup

Before you can start chatting with other users you must first set up an Activity that will handle the conversation functionality. This conversation Activity will be the core of your chat app and will be used by other Delivered SDK components covered in the various sections of the documentation.

Creating a conversation Activity

Start up by creating a new Activity and adding the DeliveredConversationFragment provided by the Delivered SDK. This component is responsible for sending and displaying messages in a conversation:

public class ConversationActivity extends AppCompatActivity {
        
   private DeliveredConversationFragment mConversationFragment;
        
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        mConversationFragment = DeliveredConversationFragment.newInstance(chatId);
        fragmentTransaction.add(R.id.conversation_fragment_container, mConversationFragment);
        fragmentTransaction.commit();
	}
	
	...
	
}

Notice in the code snippet above that the DeliveredConversationFragment.newInstance() takes a parameter called chatId. You can pass an empty string for now, as the reason for this will be explained in the next step.

Next, you must let the Delivered SDK know this will be the Activity used for handling all your conversations. To do this call the DeliveredSdk.setNavigation() method passing the InAppNavigation interface from within your Application class as shown here:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        
        DeliveredSdk.setNavigation(new InAppNavigation() {
            @Override
            public Intent getConversationActivity() {
                return new Intent(getApplicationContext(), ConversationActivity.class);
            }
        });
    }
}

Inside the getConversationActivity overridden method body you must return an Intent pointing to the conversation Activity you just created. This Intent will be used by Delivered SDK components to launch the conversation Activity when needed.

The last thing to do now is add the following lines to the conversation Activity you created in the first step:

public class ConversationActivity extends AppCompatActivity {
   ...
            
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    
	    String chatName = "";
	    String chatId = "";
	     
	    if (getIntent().getExtras() != null) {
	        mChatId = getIntent().getExtras().getString(EXTRA_CHAT_ID);
	        chatName = getIntent().getExtras().getString(EXTRA_CHAT_NAME);
	    }
	    
	    // The DeliveredConversationFragment is initialised here ...
	}
	
	...
	
}

First we obtain the chatId and chatName extras from the launching Intent. This extras are provided by the Delivered SDK and can be retrieved using the EXTRA_CHAT_ID and EXTRA_CHAT_NAME constants from the DeliveredConversationFragment.

Next, we must pass the chatId to the DeliveredConversationFragment.newInstance() method. As for the chatName string, you can use it to display the chat name anywhere you want in your conversation Activity.

One all the previous steps are done your conversation Activity code should look like this:

public class ConversationActivity extends AppCompatActivity {
        
   private DeliveredConversationFragment mConversationFragment;
        
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    
	    String chatName = "";
	    String chatId = "";
	     
	    if (getIntent().getExtras() != null) {
	        mChatId = getIntent().getExtras().getString(EXTRA_CHAT_ID);
	        chatName = getIntent().getExtras().getString(EXTRA_CHAT_NAME);
	    }
	    
        if (findViewById(R.id.conversation_fragment_container) != null) {
            if (savedInstanceState != null) {
                return;
            }

            mConversationFragment = DeliveredConversationFragment.newInstance(mChatId);
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.conversation_fragment_container, mConversationFragment).commit();
        }
	}
	
	...
	
}

And that’s it! Once your conversation Activity is ready it should look like this:

conversation_empty.png

The DeliveredConversationFragment provides an input area where you can write messages. Supported input types are: text (including emojis), images from local storage, and a GIFs provided by Giphy. The input area also provides an integrated camera you can use to capture images without leaving the application.

emoji.png image.png camera.png gif.png

Now that the conversation Activity is ready, your initial set up is complete. Head up to the Public group chats or One-to-one chats for instructions on how to create your first chat.