Course Content

Course Content

Connecting as a Client

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 LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
App Store
397K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
13K+ Reviews
App Download Section Circle 3
  • 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