I'm trying to use my Android phone as a handsfree kit (like the one for cars) in order to connect to another phone (any phone) and perform some handsfree functionality like (answer an incoming call, reject,.. etc) which can be done using the AT commands for handsfree profile. For that, I'm using the well-known Bluetooth chat App, and reflection work around in order to establish a connection with any device:
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); tmp = (BluetoothSocket) m.invoke(device,1);
However, in order to achieve the handsfree functionality and understand the AT commands that I'm sending, the connected phone needs to be over the handsfree profile which uses the UUID: "0000111f-0000-1000-8000-00805F9B34FB"
Therefore, is there a way to achieve a connection to the handsfree profile?
Thanks!
A Bluetooth profile is a wireless interface specification for Bluetooth-based communication between devices, such as the Hands-Free profile. For a mobile device to connect to a wireless headset, both devices must support the Hands-Free profile.
In Bluetooth, pairing enables two Bluetooth devices to communicate with each other. For devices to find and identify each other so they can communicate, one or both must be discoverable, which means they broadcast a Bluetooth signal other devices can detect and connect to.
Unfortunately, as long as your Bluetooth device is on and visible to nearby Bluetooth devices, anyone can connect to your device. If the intruder has malicious intent and technical expertise they can hack into your device and install malicious software. However, with the right precautions, you can avoid this situation.
You should only use this code when you have no other choice. The 1
in this code is the RFCOMM port. Each service has it's own RFCOMM port. This port is usually random between 1 and 31. You need to know which port the service (here handsfree profile) is using on the device that you want to connect to. You have to use the createRfcommSocketToServiceRecord
method from the BluetoothDevice
object to do this:
try { clientSocket = bluetoothDevice.createRfcommSocketToServiceRecord( serviceUUID ); }
catch (IOException e)
{
// handle error
}
This code is the correct way to use Bluetooth and should replace the one you're using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With