Github android bluetooth chat
Android BluetoothChat Sample
This sample shows how to implement two-way text chat over Bluetooth between two Android devices, using all the fundamental Bluetooth API capabilities.
This sample should be run on two Android devices at the same time, to establish a two-way chat over Bluetooth between the devices. Select «Made discoverable» in overflow menu on one device and click on the Bluetooth icon on the other one, to find the device and establish the connection.
The sample demonstrates the following, using the Bluetooth API:
- Setting up Bluetooth
- Scanning for other Bluetooth devices
- Querying the local Bluetooth adapter for paired Bluetooth devices
- Establishing RFCOMM channels/sockets
- Connecting to a remote device
- Transfering data over Bluetooth
- Android SDK 26
- Android Build Tools v26.0.1
- Android Support Repository
This sample uses the Gradle build system. To build this project, use the «gradlew build» command or use «Import Project» in Android Studio.
- Google+ Community: https://plus.google.com/communities/105153134372062985968
- Stack Overflow: http://stackoverflow.com/questions/tagged/android
If you’ve found an error in this sample, please file an issue: https://github.com/googlesamples/android-BluetoothChat
Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
Copyright 2017 The Android Open Source Project, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the «License»); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an «AS IS» BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Источник
Github android bluetooth chat
Android Bluetooth Chat 💬 App 📱
Android Bluetooth Chat application is an application written in Java language.
It is a project created by synchronizing with chat to learn the Bluetooth structure.
What is Bluetooth ⁉️
Bluetooth is a wireless communication technology that enables the wireless transmission of data over short distances. Bluetooth can communicate with 2.4 GHz using radio frequencies. Bluetooth technology can reach up to 10 meters of shooting capacity in an open area. Data transfer speeds between 1 Mbps and 721 Kbps are achieved in transfers with Bluetooth.
Android OS supports networking via Bluetooth. It transfers data between devices using wireless communication.
By using Android Bluetooth APIs, we can easily access Bluetooth related functions.
It allows to connect to other devices using the Bluetooth API.
What can we do using Bluetooth APIs ❓
- Scan for other Bluetooth devices
- Questioning Bluetooth devices paired with the device
- Transferring data with other devices
- Connecting to other devices with services
- Managing multiple wireless connections
Источник
Github android bluetooth chat
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.
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 👍 |
- 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! 💬
📖 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 .
Next, add the Bluetooth chat library in app level build.gradle and sync the gradle file.
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.
Once interface is implemented, create an object either server or client whichever you require and use its features to develop Bluetooth chat system.
Here are the available library APIs which you can use to develop a Bluetooth chat system.
Method | Description |
---|---|
sendMessage(message) | Sends message to client. |
onDestroy() | Close the chat room. |
Method | Description |
---|---|
sendMessage(message) | Sends message to server. |
onDestroy() | Leave the chat room. |
Field | Value | Description |
---|---|---|
NOTIFICATION | 0 | The message is alert or notification. |
GENERAL_MESSAGE | 1 | The message received from server or client. |
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)
About
An Android sample application which users can chat each other via Bluetooth technology. No Wi-Fi required!
Источник
Github android bluetooth chat
Bluetooth Low Energy Chat example
I took the original Bluetoot Chat example from Google and modified it to run as a Bluetooth Low Energy (BLE) GATT service.
This is just a proof of concept to see how the Android BLE API works in a real world, and test some use-cases/scenarios like:
- Connect devices and see how much can we done without user interactions
- Playoing with different pairing/security mechanisms
- Advertising ranges
- Test transfer rate speeds
- Mixing Bluetooth Classic with Bluetooth LE
- .
Do not expect a production-like code, don’t even expect a fully working program. The point of this experiment is just for researching Bluetooth capabillities on Android devices, not to deliver a messenger app.
What can I do and how?
This what you can do with the application so far:
Connect via Classic Bluetooth (CBT) methods
- You need at least two devices running the app, one will be the server and the other the client. In the server side, tap in the menu (upper right) and then tap on CBT — Make discoverable option.
- In the client side, tap in one of the CBT prefixed options to connect using a secure method (pairing/encrypted) or insecure method (unpairing/unencrypted). 3 If there’s no previously paired phones yet, you need to tap on the «Scan for devices» to find the server and tap on it to initiate a connection.
Connect via BLE methods
- You need at least two devices running the app, one will play the role of Peripheral (server), and the othe will be the Central device (client). In the Peripheral side, tap in the menu (upper right) and then tap in the BLE — Advertise option.
- In the Central device, tap in the BLE — Discover option, a new screen will show up with a list of devices found. Select the Peripheral device in the list and tap on it to initiate a connection.
Send messages (CBT and BLE)
- Just write the message you want to send in the box below
- Tap on SEND button.
- Write «/send» and you will see a new screen with your Gallery photos.
- Choose one picture and it will be send to the other device. The image is going to be send via RFCOMM Socket, so the transfer rate should be the highest possible.
WARNING: You need to be previously connected via BLE.
Test trasnfer rate
- Write «/transfertest» and it will show you a progress bar in both the Peripheral and Central devices. This test will try send 1MB of data. The transfer rate speed in Megabytes/Second can be shown in the screen of Peripheral device in real time.
WARNING: You need to be previously connected via BLE.
As I took the Google BluetoothChat exmaple to add all BLE capabilities on top of it, I tried to separate both BLE and CBT code in differente Java packages, so I created a new package called com.example.android.ble , where you can see some classes and interfaces. However there are only 2 importante classes to take a look: BLECentralHelper and BLEPeripheralHelper , represting all Central and Peripheral implementations respectively. Another important class is BluetoothChatFragment ( com.android.example.bluetoothchat ), which is the original one but with all the logic to communicate with BLECentralHelper and BLEPeripheralHelper .
Juan Gómez [:_AtilA_]
About
he Android Bluetooth Chat example from Google, modified to run as a Bluetooth LE GATT service.
Источник
Github android bluetooth chat
Example bluetooth chat app using Bluetooth LE library to communicate between android devices
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
This repository contains an open source sample application of the BluetoothCommunicator library.
The library, using Bluetooth Low Energy, allows you to communicate in P2P mode between two or more android devices in a very simple way.
The application is a Bluetooth chat, when the app is open in the first screen (search) it discovers nearby devices with the app open in the same search screen and shows them in a list containing the code number name of the phones (the name is customizable in the library, but not in the app).
When the user clicks on one of the names the app sends a connection request to that phone and if the latter accepts it, both apps start the chat screen where the two devices can send text messages (the library can send also raw data) to each other.
When one of the user press the back button the connection stops and the apps will return to the search screen.
If you want to see the demo app in action you can download it from here.
BluetoothCommunicator is a library originally created for RTranslator but can be used in any more generic case where a P2P communication system is needed between two or more android devices (approximately up to 4 with a direct connection between all devices, even more with a star structure), for an example app see this repository or RTranslator.
BluetoothCommunicator automatically implements (they are active by default):
reconnection in case of temporary connection loss.
reliable message sending:
splitting and rebuilding of long messages.
sending messages with a queue in order to always send the messages even in case of connection problems (they will be sent as soon as the connection is restored) and in the right order.
For use the library in a project you have to add jitpack.io to your root build.gradle (project):
Then add the last version of BluetoothCommunicator to your app build.gradle
To use this library add these permissions to your manifest:
If you need to use bluetooth advertising or search in background you need to add also the following permission:
Then add android:largeHeap=»true» to the application tag in the manifest:
Example
After the installation of the library and the changes to the manifest is time to write the code: create a bluetooth communicator object, it is the object that handles all operations of bluetooth low energy library, if you want to manage the bluetooth connections in multiple activities I suggest you to save this object as an attribute of a custom class that extends Application and create a getter so you can access to bluetoothCommunicator from any activity or service with:
Next step is to initialize bluetoothCommunicator, the parameters are: a context, the name by which the other devices will see us (limited to 18 characters and can be only characters listed in BluetoothTools.getSupportedUTFCharacters(context) because the number of bytes for advertising beacon is limited) and the strategy (for now the only supported strategy is BluetoothCommunicator.STRATEGY_P2P_WITH_RECONNECTION)
Then add the bluetooth communicator callback, the callback will listen for all events of bluetooth communicator:
Finally you can start discovery and/or advertising:
All other actions that can be done are explained with the comments in the code of callback I wrote before. For more details see the code of this example app
For anyone who wants to examinate the library code and generate the .aar file after clone the library on Android Studio: click on the «Gradle» tab in the right edge of Android Studio, then click on BluetoothCommunicator -> app -> Task -> build -> assemble, then go to the local folder of the BluetoothCommunicator project and click on app -> build -> outputs -> aar, here will be the debug and release .aar files
Bugs and problems
Avoid to have installed on your phone multiple apps that use this library, because in that case the bluetooth connection will have problems (maybe it is due to the fact that they are running advertising with the same UUID, try downloading the source files and changing the advertising UUID in the code if you want to try to fix). In case you have multiple apps using this library, uninstall all but one of them and restart your device in case of problems.
About
Example bluetooth chat app using Bluetooth LE library to communicate between android devices
Источник