Jump to: navigation, search

Android Sample

You can download the sample application package via a zip file:

Genesys Mobile Services 8.1.2 Android Sample

You can also download the source code via a zip file:

Genesys Mobile Services 8.1.2 Android Sample Source Code


Overview

The Genesys Mobile Services (GMS) Android sample illustrates how to implement an Android app that communicates with GMS and performs supported contact scenarios. It is primarily meant to be used by developers as a reference to build an Android app with GMS.

This sample app can also be used to test an existing GMS deployment, because the scenario parameters are configurable on the GMS Service Management UI.

Implemented Scenarios

The Android sample supports the scenarios described in the Callback Scenarios. These scenarios are server-driven, which means that the server instructs the client with the actions needed to carry out the scenario. The client just needs to perform those actions and follow up dialog with the server. Therefore, the client is flexible enough to support any scenario that is built using the same kind of actions. The following actions are supported:

  • DialNumber - The app makes a phone call.
  • ConfirmationDialog - The app displays a message.
  • DisplayMenu - The app displays a menu for the user to select an item that may affect how the scenario proceeds.
  • StartChat - The app starts a chat conversation. Asynchronous HTTP notifications (comet messages) are used for receiving chat server events.

Push notifications through Google Cloud Messaging are supported. Delayed scenarios are supported by using push notifications only; the app will not poll the server to be notified about agent availability.

Prerequisites

In order to use the Android sample app, you need to have GMS installed and running, and the services that you want to make use of have to be deployed.

Running the Sample

In order to run the Android sample, you can just download the APK file and deploy it on your Android device. Alternatively, you can also compile the source code to make your own APK file by using the Android SDK. Using the sample is easy, as long as GMS is already deployed.

The startup screen is a configuration screen:


Startup Screen


Remember that in order for push notifications to work, you need to have registered a project in Google Cloud, and have enabled the Google Cloud Messaging (GCM) for Android API. In the app, you have to fill the GCM sender id with your Google Cloud project number. For more details, please refer to Google Cloud Messaging - Getting Started.

After you have filled the configuration options with the appropriate values for your GMS environment, you can scroll to the bottom of the screen and click Go! for one of your configured services:


Startup Screen at the bottom


In order to review in detail the past communication between the client and the server, you can use the Log screen, which you can open from the Show logs option in the startup screen.


Log Screen


You can also inspect the standard Android logging, by using the Android logcat tool, for obtaining more details or displaying logs more comfortably on your computer screen. Filter by the GenesysService tag in order to see the client-server communication.

Small Introduction to the Code

The app is designed to be minimal, so that developers can focus on the implementation of Mobile Services scenarios.

The app consists of three screens (Android activities):

  • GenesysSampleActivity - Displays the app configuration options, allows launching the Mobile Services scenarios, and interprets the server-driven actions.
  • GenesysChatActivity - Chat screen.
  • LogActivity - Displays logs.

The GenesysSession class is in charge of the client-server communication via HTTP for a Mobile Services user session, including comet notifications. It relies on the Jetty HTTP Client, and on the CometD Java Client. GenesysSession can be reused "as is" in your code. (Note: this is provided as sample code, so always test your app thoroughly. See the disclaimer below.)

The GenesysService class implements an Android service responsible for creating GenesysSession objects and keeping them running in the background, even when the user switches to other apps. GenesysService distributes server responses and comet messages to the preceding activities.

The GenesysCloudMessageReceiver class is in charge of receiving push notifications. It is implemented following Android recommendations, using the Google Play Services library. See Google Cloud Messaging - Implementing GCM Client.

The ChatSession class and some companion classes implement chat operations. These classes are meant to be reusable in your code. (See the disclaimer below).

Disclaimer

THIS CODE IS PROVIDED BY GENESYS TELECOMMUNICATIONS LABORATORIES, INC. ("GENESYS") "AS IS" WITHOUT ANY WARRANTY OF ANY KIND. GENESYS HEREBY DISCLAIMS ALL EXPRESS, IMPLIED, OR STATUTORY CONDITIONS, REPRESENTATIONS AND WARRANTIES WITH RESPECT TO THIS CODE (OR ANY PART THEREOF), INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. GENESYS AND ITS SUPPLIERS SHALL NOT BE LIABLE FOR ANY DAMAGE SUFFERED AS A RESULT OF USING THIS CODE. IN NO EVENT SHALL GENESYS AND ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, ECONOMIC, INCIDENTAL, OR SPECIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ANY LOST REVENUES OR PROFITS).

This page was last edited on August 20, 2018, at 14:03.
Comments or questions about this documentation? Contact us for support!