Git Product home page Git Product logo

stream-chat-android's Introduction

stream-chat-android

Build Status version Component Reference

๐Ÿšจ SDK is in transition period between:

stream-chat-android is the official Android SDK for Stream Chat, a service for building chat and messaging applications. This library includes both a low level chat SDK and a set of reusable UI components. Most users start out with the UI components, and fall back to the lower level API when they want to customize things.

Quick Links

Java/Kotlin Chat Tutorial

The best place to start is the Android Chat Tutorial. It teaches you how to use this SDK and also shows how to make common changes. You can use either Java or Kotlin depending on your preference.

Clone the Github Example App

This repo includes a fully functional example app. To run the example app:

git clone [email protected]:GetStream/stream-chat-android.git

Open the project in Android Studio. Setup your emulator (we're using Pixel 3, API 29 at the moment). Note that the gradle sync process can take some time when you first open the project.

Docs

This library provides:

  • A low level client for making API calls and receiving chat events
  • Livedata objects + Offline support (using Room)
  • 4 reusable chat views

** Channel List ** Message List ** Message Input ** Channel Header

The documentation for livedata and the custom views is available here: https://getstream.io/chat/docs/android_overview/?language=kotlin

Chat API

The low level Chat API docs are available for both Kotlin and Java.

Supported features

  • Channels list UI
  • Channel UI
  • Message Reactions
  • Link preview
  • Images, Videos and Files attachments
  • Edit and Delete message
  • Typing Inditicators
  • Read Inditicators
  • Push Notifications
  • Image gallery
  • GIF support
  • Light/Dark themes
  • Style customization
  • UI customization
  • Threads
  • Slash commands
  • Offline support
  • Markdown messages formatting

Installing the Java Chat SDK

  • Step 1 Add repository into root build.gradle
allprojects {
    repositories {
    ...
    maven {
        url 'https://jitpack.io' }
    }
}
  • Step 2 Add library dependency into app build.gradle

See the jitpack badge above for the latest version number

android {
    ...
    dataBinding {
        enabled = true
    }
	
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'com.github.getstream:stream-chat-android:<latest-version>'
}

Proguard/R8

If you're using Proguard/R8 you'll want to have a look at the proguard file we use for the sample.

Setup Stream Chat

Make sure to initialize the SDK only once; the best place to do this is in your Application class.

public class BaseApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        StreamChat.init("STREAM-API-KEY", getApplicationContext());
    }
}

If this is a new Android app you will need to register BaseApplication inside AndroidManifest.xml as well.

...

<application
    android:name=".BaseApplication"
    ...
>

...

</application>

With this you will be able to retrieve the shared Chat client from any part of your application using StreamChat.getInstance(). Here's an example:

public class MainActivity extends AppCompatActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Client client = StreamChat.getInstance(this.getApplication());
		...
	}

Make sure that your AndroidManifest.xml file include INTERNET and ACCESS_NETWORK_STATE permissions:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="...">

    ... 

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    ...

</manifest>    

Online status

Connection status to Chat is available via StreamChat.getOnlineStatus() which returns a LiveData object you can attach observers to.

StreamChat.getOnlineStatus().observe(...);

Markdown support

Markdown support is based on Markwon: 4.1.2. Currently SDK doesn't support all Markwon features and limited to this plugins:

If you want to use another library for Markdown or extend the Markwon plugins you can use the code below

MarkdownImpl.setMarkdownListener((TextView textView, String message)-> {
    // TODO: use your Markdown library or the extended Markwon.
});

Debug and development

Logging

By default logging is disabled. You enable logs and set log level when initialising StreamChat:

StreamChatLogger logger = new StreamChatLogger.Builder()
                .loggingLevel(BuildConfig.DEBUG ? StreamLoggerLevel.ALL : StreamLoggerLevel.NOTHING)
                .build();

StreamChat.Config configuration = new StreamChat.Config(this, "api-key");
configuration.setLogger(logger);
StreamChat.init(configuration);

If you need to intercept logs you can pass logger handler:

StreamChatLogger logger = new StreamChatLogger.Builder()
                .setLoggingHandler(loggerHandler)
                .build();

Editing this library

This guide assumes that you're working on your own project in the project folder and clone the chat SDK library in a separate folder.

  1. First of all you'll want to clone this repo
git clone [email protected]:GetStream/stream-chat-android.git
  1. Next you'll edit your project's settings.graddle and add this
include ':chat'

project(":chat").projectDir=new File("ABSOLUTEPATHTOstream-chat-android here")
  1. Open up your project/app/build.gradle and replace the production SDK with your local copy
//implementation 'com.github.getstream:stream-chat-android:3.6.2'
implementation project(':chat')
  1. Next open up project/build.gradle.

Add the following to the buildscript {} entry


buildscript {
...

    ext {
        googleServiceVersion = '4.3.2'
        gradleVersion = '3.5.2'
        gradlePluginVersion = '2.1'
        jacocoVersion = '0.1.4'
        mannodermausVersion = '1.5.1.0'

    }
    
...
}

Next in the dependencies setup these libraries. (They are needed to compile stream-chat-android

buildscript {
	dependecies {
	....
	
	classpath "com.android.tools.build:gradle:$gradleVersion"
        classpath "com.github.dcendents:android-maven-gradle-plugin:$gradlePluginVersion"
        classpath "com.google.gms:google-services:$googleServiceVersion"
        classpath "de.mannodermaus.gradle.plugins:android-junit5:$mannodermausVersion"
        classpath "com.dicedmelon.gradle:jacoco-android:$jacocoVersion"
	}
}

Hit build/clean project in android studio and build your app.

FAQ

Channel List loading icons spins forever

Not setting the lifecycle owner on a data binding can cause the channel list loading icon to spin forever

mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_chat, container, false);
mBinding.setLifecycleOwner(this);

It's also possible that the permissions for your app are cached. Try uninstalling the app from your emulator and reinstalling to ensure you have the permissions required by this library.

Images are not loaded

In most cases you can try to see the reason in logcat with tag Glide. One of the reasons is that app tries to load image from http url, but not https. To fix it you need to define network security config.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <!-- Keep in mind this example allows to make any http request, to define proper security config read Android documentation-->
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

And update your Manifest:

<application
	android:networkSecurityConfig="@xml/network_security_config"/>

Localize the UI with Translations

You can translate all strings of SDK by overriding string keys.
The example app has a few examples:

stream-chat-android's People

Contributors

adrian09h avatar tbarbugli avatar tschellenbach avatar andriizhumela avatar elevenetc avatar bevzaanton avatar jeffdgr8 avatar jmfayard avatar tilton avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.