我的蓝牙连接到诺基亚但未连接到 android

My bluetooth connected with nokia but not connected with android

我正在 android studio 中制作蓝牙应用程序,一切正常,当我将蓝牙与我的 android 手机连接时出现问题,它没有连接,但是当我将它与我的兄弟 c2-02 连接时,它是现在已连接,为什么?????

我的连接线程如下

     private class ConnectThread extends Thread {
         private final BluetoothSocket mmSocket;
         private BluetoothAdapter mybluetoothAdapter;
         private final BluetoothDevice mmDevice;
         private final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
         public ConnectThread(BluetoothDevice device) {
             BluetoothSocket tmp = null;
             mmDevice = device;
             try {
                 tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
             } catch (IOException e) { e.printStackTrace(); }
             mmSocket = tmp;
         }


         public void run() {
             //mybluetoothAdapter.cancelDiscovery();
             try {
                 mmSocket.connect();
             } catch (IOException connectException) {
                 try {
                     mmSocket.close();
                 } catch (IOException closeException) { closeException.printStackTrace(); }
                 return;
             }

         }
         public void cancel() {
             try {
                 mmSocket.close();
             } catch (IOException e) { e.printStackTrace();  }
         }
     } 

您似乎没有正确使用 createRfcommSocketToServiceRecord()。 您使用该方法之前,您需要将您的移动设备与您要与之通信的设备配对。你应该阅读 http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createRfcommSocketToServiceRecord(java.util.UUID).

您可以尝试使用 createInsecureRfcommSocketToServiceRecord() 来验证您没有其他问题。但我怀疑因为它适用于一台设备而不适用于另一台设备,所以你只是没有在它不起作用的地方配对移动设备。