我正在为两个玩家构建tic tac,需要蓝牙连接来交换一些数据,我可以启用蓝牙,启用发现能力,但我在“BluetoothServerSocket”和客户端“BluetoothSocket”中的问题,我不知道如何操作这部分,这是代码:
ArrayList<String>al=new ArrayList<String>();
BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = ba.getBondedDevices();
if(pairedDevices.size()>0)
for(BluetoothDevice d: pairedDevices)
al.add(d.getName()+" , "+d.getAddress());
if (!ba.isEnabled())
ba.enable();
BluetoothDevice device;
Intent dis=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
dis.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,300);
startActivity(dis);
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(UUID);
socket.connect();
InputStream is=socket.getInputStream();
OutputStream os=socket.getOutputStream();