Something like this:
String addr = args[0];
log("Connecting over bluetooth to " + addr);
bs = null;
try {
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(addr);
mBluetoothAdapter.cancelDiscovery();
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
bs = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));
bs.connect();
} catch (Exception e) {
return false;
}
You need the MAC address of the device to which you are going to connect, and then just use the InputStream and OutputStream of bs
.