In-app Chat
  • iOS
  • Android : Java
  • Web
  • Flutter
  • React Native
  • Unity3D
  • Windows
  • macOS
  • Introduction
    • Overview
    • Basic concepts
  • Sample app
  • Getting started
  • Client SDKs
    • SDK downloads
    • Release notes
  • Guides
    • Users
    • Authentication
    • Manage users
    • Room
    • Group
    • Messaging
    • Call invitation (signaling)
    • Manage sessions
  • Offline push notifications
  • Error codes
  • Client APIs
  • Server APIs
  • Documentation
  • In-app Chat
  • Sample app

Sample app

Last updated:2023-09-27 10:16
Sample app
Download

Here we provide you with a sample application to experience ZEGOCLOUD's In-app Chat, and also describe how to run the sample code.

Prerequisites

  • Android Studio 2.1 or later.
  • Android SDK Packages: Android SDK 28, Android SDK Platform-Tools 28.x.x or later.
  • An Android device or Simulator that is running on Android 4.1 or later and supports audio and video. We recommend you use a real device (Remember to enable the USB debugging).
  • The Android device is connected to the internet.
  • Contact the ZEGOCLOUD Technical support to get the AppID and ServerSecret for SDK integration.
  • Get the token that SDK required for login authentication. For details, see Authentication.
  • When you compile the sample code for the first time, if you do not have the corresponding dependent library or build tool, Android Studio will automatically download the sample code. This may take a while for you to wait.
  • We recommend you download the specified gradle and required dependencies. To download, go to Gradle Services. The gradle we use in the sample code are as follows:
    • gradle: 4.6 (check it in the project/gradle/wrapper/gradle-wrapper.properties file).
    • gradle Android plug-in: 3.2.1 (check it in the project/build.gradle file).

Sample code structure

The following structure shows the subdirectory structure of the In-app Chat sample code:

.
├── app
│   ├── agconnect-services.json
│   ├── build
│   │   ├── generated
│   │   ├── intermediates
│   │   ├── outputs
│   │   └── tmp
│   ├── build.gradle
│   ├── libs
│   │   ├── MiPush_SDK_Client_4_9_1.jar
│   │   ├── VERSION.txt
│   │   ├── ZIM.jar
│   │   ├── arm64-v8a
│   │   ├── armeabi-v7a
│   │   ├── pushOpenClient_v3.0.0.4_484_81c1f83_release.jar
│   │   ├── x86
│   │   ├── x86_64
│   │   └── zpns-release.aar
│   ├── proguard-rules.pro
│   ├── src
│   │   └── main
│   └── zim_example_key.jks
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── local.properties
└── settings.gradle

Run the sample code

  1. In Android Studio, click Open an Existing Project.

  2. Open the ZIMExampleJava folder in the unzipped sample code package.

    /Pics/ZIM/Android/demo.png

  3. Go to the SDK downloads to download the latest version of SDK, copy the unzipped SDK package file to the app/libs directory.

  4. Modify the KeyCenter.java file under the ZIMExample/app/src/main/java/im/zego/zimexample folder with the AppID and ServerSecret (remember to add a "L" after the AppID) that you get in the Prerequisites steps.

    /Pics/ZIM/Android/fill_appid_appSign_in_android_demo_new2.png

  5. Connect the Android device to your computer, after you enabled the developer mode and USB debugging on the device, the option box in the upper place of Android Studio changes like the following, which means you are ready to run the sample code on the Android device.

    Before:

    /Pics/ZIM/Android/as_no_device_new.png

    After:

    /Pics/ZIM/Android/as_connected_device_new.png

<div class = 'mk-hint'>

- When you connect your PC to an Android device, a message will pop up on most devices. The message varies according to Android vendors. You can select USB mode according to the actual situation.
- After the Android device is connected to your computer, you will need to enable the **developer mode*8 and **USB debugging** on the device based on the actual situation. You can search for specific enabling methods by yourself.
</div>
  1. Click the Run button to run the sample code and experience the In-app Chat service.
    /Pics/ZIM/Android/run_android_demo_new.png

FAQ

This error error: incompatible types: unexpected return value occurs when Android Studio runs the sample code.

/Pics/ZIM/Android/as_run_android_demo_error_33.png

The AppID and ServerSecret in our sample code This is because there are no specific values for AppID and ServerSecret in the sample code you downloaded. Please follow the Prerequisites to get the AppID and ServerSecret first and try again.

Page Directory