我正在爲兩個玩家建立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();