Skip to content

sung2063/AndroidBluetoothChatLibrary

Repository files navigation

Android Bluetooth Chat Library

Bluetooth Chat Library provides tools for communication between a server and client over Bluetooth. It also serves as a supporting tool to help people maintain social distancing during the COVID‑19 pandemic.

💖 Sponsor

Android Bluetooth Chat updates regularly. Your valuable sponsorship helps me contributing more features and maintaining the library. Support me for building more interesting projects! 💜

🎬 Sample GIF Image

Android Bluetooth Chat App - No internet required 👍

📖 How to Use Bluetooth Chat Library

1. Setup your Android project setting

Minimum SDK Version: 21 or greater (Update in your app level build.gradle)
Supported Programming Language: Java

2. Add required library

First, include following jitpack url inside maven block in your project level build.gradle.

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Next, add the Bluetooth chat library in app level build.gradle and sync the gradle file.

implementation 'com.github.sung2063:AndroidBluetoothChatLibrary:1.02'

Now you are ready to use BluetoothChat library and it has two different roles:

  • Server - Creates the room and communicate with client user
  • Client - Joins the existing room and communicate with server user

Start with implementing each methods of EventListener interface on Activity.

EventListener eventListener = new EventListener() {

 @Override
 public void onConnected() {
    // TODO: Implement the method
 }

  @Override
  public void onNotified(final int notificationType) {
    // TODO: Implement the method
  }

  @Override
  public void onReceived(final String message) {
    // TODO: Implement the method
  }

  @Override
  public void onErrorOccurred(ErrorDataModel errorData) {
    // TODO: Implement the method
  }
};

Once interface is implemented, create an object either server or client whichever you require and use its features to develop Bluetooth chat system.

ServerConnectivity serverConnectivity = new ServerConnectivity(this, eventListener);      // Create a server object
ClientConnectivity clientConnectivity = new ClientConnectivity(this, eventListener);      // Create a client object

📚 Library APIs

Here are the available library APIs which you can use to develop a Bluetooth chat system.

ServerConnectivity

Method Description
sendMessage(message) Sends message to client.
onDestroy() Close the chat room.

ClientConnectivity

Method Description
sendMessage(message) Sends message to server.
onDestroy() Leave the chat room.

IncomingType

Field Value Description
NOTIFICATION 0 The message is alert or notification.
GENERAL_MESSAGE 1 The message received from server or client.

Notification

Field Value Description
NOTIFICATION_ROOM_ESTABLISH 0 The notification when room is established.
NOTIFICATION_SELF_ENTER 1 The notification when client enters the room on client side.
NOTIFICATION_ENTER 2 The notification when client enters the room on server side.
NOTIFICATION_LEAVE 3 The notification when client leave the room.

🌟 Contributor

Sung Hyun Back (@sung2063)

📝 License

The code is licensed under the GNU General Public License.

About

An Android library which supports tools to communicate server and client via Bluetooth technology.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages