Bluetooth connect without pairing
<p>The normal way to connect to a bluetooth device is by pairing.</p>

<p>We need to connect to a device in an abnormal way:  By using the Bluetooth MAC address only.  We do not want to be prompted for a PIN.</p>

<p>We know the device supports this technique, but we cannot find a way to do it on Android.</p>

<p>The abbreviated code looks like this:</p>

<pre><code>  String mac_address = “00:11:22:33:44:55”
  BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

  BluetoothDevice bluetoothDevice = mBluetoothAdapter.getRemoteDevice(mac_address);

  Method m = bluetoothDevice.getClass().getMethod("createRfcommSocket", 
           new Class[] {int.class});
  BluetoothSocket socket = (BluetoothSocket) m.invoke(device, 1);

  socket.connect();
</code></pre>

<p>The problem is that upon <code>socket.connect()</code> we are prompted for a PIN.  The PIN is not necessary for this device, so we do not want to be prompted for a PIN.</p>

<p>The reason we know the PIN is not necessary:</p>

<ol>
<li>We manufacture this device and write the firmware.</li>
<li>We can connect to it using a program on windows written in C#.</li>
</ol>

<p>How can we modify the code such that it will not prompt for a PIN?</p>

<p>[Edit to test suggestion in comment]</p>

<p>We tested method createInsecureRfcommSocketToServiceRecord like this:</p>

<pre><code>ParcelUuid list[] = device.getUuids();
BluetoothSocket  socket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(list[0].getUuid());
</code></pre>

<p>Then we get error like this:</p>

<pre><code>I/InputDispatcher(  382): Delivering touch to current input target: action: 0x1
I/InputDispatcher(  382): Delivering touch to current input target: action: 0x1
V/BluetoothSocket.cpp(16956): initSocketNative
V/BluetoothSocket.cpp(16956): ...fd 66 created (RFCOMM, lm = 0)
V/BluetoothSocket.cpp(16956): initSocketFromFdNative
I/BluetoothPolicyService(  382): getBluetoothDataTransferAllowed
D/BluetoothUtils(16956): isSocketAllowedBySecurityPolicy start : device null
V/BluetoothService.cpp(  382): createDeviceNative
V/BluetoothService.cpp(  382): ... address =
V/BluetoothEventLoop.cpp(  382): onCreateDeviceResult
V/BluetoothEventLoop.cpp(  382): onCreateDeviceResult
E/BluetoothEventLoop.cpp(  382): onCreateDeviceResult: D-Bus error: org.bluez.Error.AlreadyExists (Already Exists)
D/BluetoothEventLoop(  382): Result of onCreateDeviceResult:1
V/BluetoothService.cpp(  382): discoverServicesNative
V/BluetoothService.cpp(  382): ... Object Path = /org/bluez/1100/hci0/dev_00_11_22_33_44_55
V/BluetoothService.cpp(  382): ... Pattern = , strlen = 0
D/FStest  (  633): check default
D/FStest  (  633): check default
</code></pre>