简体   繁体   中英

send files from pc to mobile via bluetooth in java without pairing

I'm developing a desktop application using java to send a file to devices around. It's done but I have a problem, a pairing message appears in mobile device when a send operation tries to begin.My app uses bluecove library.Bluecove has an example application in its website to send files via Bluetooth that doesn't need pairing while sending files.download it from here http://www.bluecove.org/bluecove-examples/obex-install/push.jnlp

Here is my code which sends file to a Bluetooth device :

Connection connection = Connector.open(btConnectionURL);
// connection obtained

// now, let's create a session and a headerset objects
ClientSession cs = (ClientSession) connection;

HeaderSet hsConnectReply = cs.connect(null);
if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) {
System.out.println("Error while connecting device");
    return;
}   
HeaderSet hs = cs.createHeaderSet();
hs.setHeader(HeaderSet.NAME, filename);
hs.setHeader(HeaderSet.TYPE,
        new MimetypesFileTypeMap().getContentType(new File(filen)));
hs.setHeader(HeaderSet.LENGTH, new Long(file.length));

Operation putOperation = cs.put(hs);

OutputStream outputStream = putOperation.openOutputStream();
outputStream.write(file);
// file push complete

outputStream.close();
putOperation.close();

cs.disconnect(null);

connection.close();

the url in my case is : btgoep://001FDF08DEEC:9;authenticate=false;encrypt=false;master=false

I wonder what is the difference between my app and bluecove example app. Thanx in advance.

based on this you can do automated authentication in .net!

based on my experience in bluecove you need to override the RemoteDevice.authenticate() function and provide a hard coded pin number for server and make the number available to clients to enter for authentication! with this approach you do pairing but without need to enter manually in server side!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM