Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Connecting Bluetooth as a Client

 

In today's video our topic is Connecting Bluetooth as a client.

In order to initiate a connection with the remote device (a device holding an open server socket), we must first obtain a BluetoothDevice object that represents the remote device. Then use the Bluetooth device to acquire Bluetooth socket and initiate the connection.

Using the Bluetoothdevice get a Bluetoothsocket by calling createRfcommSocketToServiceRecord(UUID). Initiate the connection by calling connect().

Example :

private class ConnectThread extends Thread {

private final BluetoothSocket mmSocket;

private final BluetoothDevice mmDevice;

public connectThread(BluetoothDevice device)

{

BluetoothSocket tmp=null;

mmDevice=device;

tmp=device.createRfcommSocketToServiceRecord(MY_UUID);

}

catch (IOException e) { }

mmSocket=tmp;

}

When you have successfully connected two (or more) devices, each one will have a connected Bluetooth socket. Now we can share data between devices using Bluetooth socket.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere