Ciao a tutti avrei bisogno di consigli sul seguente problema:
devo scrivere un progr java come questo
(che ho reperito dal sito ufficiale di bluecove):
la classe dovrebbe implementare la ricezione di una stringa da bluetooth.codice:public class OBEXPutServer { static final String serverUUID = "11111111111111111111111111111123"; public static void main(String[] args) throws IOException { LocalDevice.getLocalDevice().setDiscoverable(DiscoveryAgent.GIAC); SessionNotifier serverConnection = (SessionNotifier) Connector.open("btgoep://localhost:" + serverUUID + ";name=ObexExample"); int count = 0; /***/ System.out.println("Waiting..."); /***/ while(count < 2) { RequestHandler handler = new RequestHandler(); serverConnection.acceptAndOpen(handler); System.out.println("Received OBEX connection " + (++count)); } } private static class RequestHandler extends ServerRequestHandler { public int onPut(Operation op) { try { HeaderSet hs = op.getReceivedHeaders(); String name = (String) hs.getHeader(HeaderSet.NAME); if (name != null) { System.out.println("put name:" + name); } InputStream is = op.openInputStream(); StringBuffer buf = new StringBuffer(); int data; while ((data = is.read()) != -1) { buf.append((char) data); } System.out.println("got:" + buf.toString()); op.close(); return ResponseCodes.OBEX_HTTP_OK; } catch (IOException e) { e.printStackTrace(); return ResponseCodes.OBEX_HTTP_UNAVAILABLE; } } } }
Tuttavia mi pare che usando le chiavette BT prima di ricevere un file è necessario "mettere in ascolto" il pc selezionando "ricevi file" dal pannello BT (non ho trovato modo di rendere questa opzione permanente). Come si può fare la stessa cosa da dentro il codice java?

Rispondi quotando