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.
Android Bluetooth Chat updates regularly. Your valuable sponsorship helps me contributing more features and maintaining the library. Support me for building more interesting projects! 💜
Android Bluetooth Chat App - No internet required 👍 |
- Clone the AndroidBluetoothChatSample repository to your local computer
- Open the project on Android Studio
- Prepare two Android devices either phone(s) or tablet(s)
- Turn on the Bluetooth on both devices and pair them each other
- Run the app on both devices
- Create a room on one device and join the room with other device
- Enjoy chatting! 💬
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
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. |
Sung Hyun Back (@sung2063)