问题描述
我写了使用蓝牙传输数据的安卓游戏。我从附带ADK蓝牙聊天应用程序复制到code。我的手机似乎并没有能够与UUID连接,所以我想用另一个方法来取代它。我已经取代我用
I have written an Android game that uses Bluetooth to transfer data. I copied the code from the Bluetooth Chat application that comes with the ADK. My phone doesn't seem to be able to connect with UUID so I would like to replace it with another methods. I have already replaced my connecting methods with
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);
和现在我不知道我怎么能听那种连接?目前,有读
and now I wonder how I can listen for that kind of connections? Currently there reads
tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,MY_UUID_SECURE);
,但这显然需要被发送的UUID。
but this obviously requires the UUID to be sent.
推荐答案
感谢史密斯先生提供给我一个答案。随着一点点的研究,我能找到的另一个StackOverflow同样的主题和问题 <一个href=\"http://$c$c.google.com/p/android-bluetooth/source/browse/branches/two_dot_o/AndroidBluetoothLibrary/src/it/gerdavax/easybluetooth/LocalDevice2Impl.java?r=58\"相对=nofollow>与我一直在寻找soluction的良好来源文件。
Thanks for Mister Smith by providing me with an answer. With a little research I was able to find an another StackOverflow question with the same subject and a good source file with the soluction I was looking for.
什么我基本上做的是与私人BluetoothAdapter适配器= BluetoothAdapter.getDefaultAdapter()来获得BluetoothAdapter;
,然后用
What I basically had to do is to get the BluetoothAdapter with private BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
and then listen for connections with
Method m = adapter.getClass().getMethod("listenUsingRfcommOn", new Class[] { int.class });
BluetoothServerSocket tmp = (BluetoothServerSocket) m.invoke(adapter, 1);
这篇关于Android的监听无连接的UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!