Skip to content Skip to sidebar Skip to footer

Android Bluetooth To Connect Another Bluetooth Device

Im doing bluetooth based application, I want to connect other devices like nokia devices, and printer. I refer the android bluetooth documentation http://developer.android.com/guid

Solution 1:

I think this is not possible.

in fact, when you create a bluetooth socket, you have to use createRfcommSocketToServiceRecord(UUID)

This function requires an UUID that is a string shared between the applications on the two devices so the connection can be established.

Without a bluetooth socket listening on the other device, with the exact same UUID, you won't be able to share data.

Solution 2:

You can do connection between two BT devices easily. You just need to call

createRfcommSocketToServiceRecord(UUID)

with UUID that understand receiver device. For file transfer action UUID must be equal (for example) to 00001106-0000-1000-8000-00805F9B34FB (File transfer service)

So you connection code might looks like code below

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice("00:0A:94:16:77:A0"); BluetoothSocket clientSocket;

try {
    log(TAG, "Remote device " + device);
    ParcelUuid[] uuids = device.getUuids();
    boolean isFileTransferSupported = false;
    UUID ftpUID = UUID.fromString("00001106-0000-1000-8000-00805F9B34FB");
    // Check if remote device supports file transferfor (ParcelUuid parcelUuid: uuids) {
        if (parcelUuid.getUuid().equals(ftpUID)) {
            isFileTransferSupported = true;
            break;
        }
    }
    if (!isFileTransferSupported) {
        log(TAG, "Remote bluetooth device does not supports file transfer ");
        return;
    }
    clientSocket = device.createRfcommSocketToServiceRecord(ftpUID);
    clientSocket.connect();
} catch (IOException e) {
    return;
}

Post a Comment for "Android Bluetooth To Connect Another Bluetooth Device"