Android蓝牙-源代码

| 数周来,我一直在努力处理Android上的蓝牙项目。有谁知道我可以去哪里查看Google用来使蓝牙配对和连接逻辑正常工作的实际代码? 我遍历了所有文档资料,BluetoothChat应用程序(无法像所宣传的那样工作……在3种不同的手机上进行了尝试),以及网上的许多其他站点,但仍然没有运气。我需要启动一个应用程序并在2.1或更高版本上运行。 任何建议或帮助,我们将不胜感激。     
已邀请:
您可以在此处浏览所有android.bluetooth软件包: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/bluetooth/BluetoothClass.java#BluetoothClass     
是的,蓝牙项目对我不起作用也是因为套接字连接的代码不起作用
 // Get a BluetoothSocket for a connection with the
            // given BluetoothDevice
            try {
                if (secure) {
                    tmp = device.createRfcommSocketToServiceRecord(
                            MY_UUID_SECURE);
                } else {
                    tmp = device.createInsecureRfcommSocketToServiceRecord(
                            MY_UUID_INSECURE);
                }
            } catch (IOException e) {
                Log.e(TAG, \"Socket Type: \" + mSocketType + \"create() failed\", e);
            }
这不起作用... 将其替换为以下代码
BluetoothDevice hxm = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(device.getAddress());
Method m;
m = hxm.getClass().getMethod(\"createRfcommSocket\", new Class[]{int.class});
socket = (BluetoothSocket)m.invoke(hxm, Integer.valueOf(1));
    
嗯,如果您在应用程序级别代码方面遇到问题,我不确定盯着蓝牙管理器源会很有帮助,但是您可以从这里开始:https://android.googlesource.com/platform/packages/apps / Bluetooth蓝牙管理器应用程序代码。 我会再次重申:说实话,这可能对您想要的内容没有帮助。您应该能够获得一个可以正常工作的蓝牙应用程序,而不必考虑这一点。 编辑:如果您想要实现蓝牙程序包(android.bluetooth)的代码,请参阅https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth。     

要回复问题请先登录注册