Android-PeerMessanger
Step 1:We need the Android Bluetooth service for this tutorial to work. In order to use Bluetooth service, declare BLUETOOTH permission in manifest file.
Step 2:Now to check whether Bluetooth is supported on device or not, we use object of BluetoothAdapter class.
Step 3:If Bluetooth is disabled then we request the user to enable it. And we perform this action by calling startActivityForResult() with REQUEST_ENABLE_BT action.
This will open dialog to enable Bluetooth on the device.
Step 4:Now in android, device is not discoverable by default. To make device discoverable, call startActivityForResult() with BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE action.
Step5:To start the chat, we first need to establish connection with the desired device. And before starting scanning for available devices, we usually get paired devices first in the list
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
Set pairedDevices = bluetoothAdapter.getBondedDevices()
Step6:To connect two devices, we must implement server side and client side mechanism. One device shall open the server socket and another should initiate the connection. Both are connected when BluetoothSocket is connected on the same RFCOMM channel.
During connection procedure android framework automatically shows pairing dialog.
Step 7: Read and Write Data
After establishing connection successfully, each device has connected BluetoothSocket.
Now one can Read and write data to the streams using read(byte[]) and write(byte[]).
forked from nilva-challenge/Android-PeerMessanger
-
Notifications
You must be signed in to change notification settings - Fork 0
hoseinnikmaram/Android-PeerMessanger
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published