Skip to content

An Android sample application which users can chat each other via Bluetooth technology. No Wi-Fi required!

Notifications You must be signed in to change notification settings

sung2063/AndroidBluetoothChatSample

Repository files navigation

Android Bluetooth Chat Sample App

Bluetooth chat application is a sample Android project which can chat with other user in anywhere, anytime without internet required.
This is also a supporting tool for helping people social distancing from COVID-19 pandamic.

💖 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 👍

🔢 Instruction

  1. Clone the AndroidBluetoothChatSample repository to your local computer
  2. Open the project on Android Studio
  3. Prepare two Android devices either phone(s) or tablet(s)
  4. Turn on the Bluetooth on both devices and pair them each other
  5. Run the app on both devices
  6. Create a room on one device and join the room with other device
  7. Enjoy chatting! 💬

📖 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)

About

An Android sample application which users can chat each other via Bluetooth technology. No Wi-Fi required!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages