Android listen for connections without UUID

限于喜欢 提交于 2019-12-06 11:29:14

问题


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 other 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);

but this obviously requires the UUID to be sent.


回答1:


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.

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);


来源:https://stackoverflow.com/questions/13362774/android-listen-for-connections-without-uuid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!