1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| mAdapter = BluetoothAdapter.getDefaultAdapter();
thBT =new BtConnecTest();
thBT.start();
class BtConnecTest extends Thread{
@Override
public void run()
{
try {
out.append("mAdapter.listing\n");
btServer = mAdapter.listenUsingRfcommWithServiceRecord("MySERVER", MY_UUID);
out.append("mAdapter listing: Success \n");
}
catch (IOException ex) {
out.append("Error : mAdapter.listing\n");
}
out.append("btServer.accept(): Waiting \n");
try {
socket = btServer.accept();
out.append("New device \n");
if(socket!=null)
{
out.append(socket.toString());
}
else
out.append("Accept : Socket is null");
} catch (IOException ex) {
out.append("Error : btServer.accept()\n");
}
if(socket!=null)
{
try {
input = socket.getInputStream();
output = socket.getOutputStream();
if(output!=null) output.write((byte)0xAC);
if(input!=null) out.append("Read = " + input.read());
} catch (IOException ex) {
out.append("getInputStream\n");
}
}
else
out.append("Last : Socket is null");
}
} |
Partager