PubNub

Build an Android chat app that can communicate cross-platform

This tutorial will guide you through downloading, building and running the telehealth chat demo for Android.  You will then optionally make some basic changes to the app.  Don’t worry if you have little or no Android experience because this tutorial is aimed at all levels but if you are comfortable with Android Studio, you might want to clone the code and skim this step.

1

Prerequisites

You’ll need the following before you begin: 

  • Android Studio, any recent version. Android Studio is available for Windows, Mac, Linux and Chrome OS.

  • Git (optional).  The source code for this demo is hosted in GitHub and git is a popular tool to obtain the source but other options exist such as downloading it as a zip.

Obtaining the Source Code

The Telehealth demo app for Android is available from https://github.com/pubnub/chat-components-android-examples.  This patient-doctor chat application uses PubNub’s Chat Components, which are pre-built UI and data building blocks to quickly create functional and visually appealing chat apps.

You can either:

Launch Android Studio and from the welcome screen and select ‘Get from Version Control’ which can be found under the three dots next to the ‘Open’ button.

Then when prompted to enter the repository URL, enter the following: https://github.com/pubnub/chat-components-android-examples and press ‘Clone’.

Or you can invoke the git tool from a terminal to clone the source code.  Navigate to an empty folder and enter the following command:

1

Or if you would rather download the source code as a zip file, click on the ‘Code’ button on GitHub and select ‘Download ZIP’.  You will need to unzip the file before you can load the source.

Other options exist, GitHub is very flexible :)

Open the code in Android Studio

If you do not already have the project loaded, launch Andriod Studio then select File → Open.

Select the directory where the source code is located and ‘Open’


IMPORTANT NOTE: If you do not see the 'telehealth-example' project in Android Studio then the most likely reason is because the files are temporarily unavailable on the master branch. To fix this, switch to the telehealth-example branch. If you are unsure how to do this please see the above video or follow this guide.


Scroll to the bottom of the project files list and open gradle.properties.  At the bottom of gradle.properties you will notice two entries for PubNub keys:

  • PUBNUB_PUBLISH_KEY  

  • PUBNUB_SUBSCRIBE_KEY

You are not ready to run the application until you obtain those PubSub keys, so that is the next step.

BackNext