Hi all,
I am trying to send file using bluetooth obex push in j2me. when i send file to my samsung star next through my appllication, connection is created and it shows that file is being transferred. however it is not saved at remote device.
Does anyone have idea why the file is not getting saved. Is there any way to know that the file is accepted on remote device?
clientSession = (ClientSession) Connector.open(connectionURL);
// connect using no headers
HeaderSet rHeaders = clientSession.connect(null);
if (rHeaders.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) {
// the connection could not be established
throw new Exception( "Remote client returned invalid response code: " + rHeaders.getResponseCode());
}
finConnection = (FileConnection) Connector.open(fileName);
fin = finConnection.openInputStream();
// create a new set of headers
HeaderSet headers = clientSession .createHeaderSet();
long totalCount = finConnection.fileSize();
headers.setHeader(HeaderSet.LENGTH, new Long(totalCount));
headers.setHeader(HeaderSet.TYPE, getMimeType(fileName));
headers.setHeader(HeaderSet.NAME, displayName);
// create an operation using the headers
op = clientSession.put(headers);
// on this operation, create the output stream
out = op.openOutputStream();
int nBytes;
byte[] bytes = new byte[1024];
while ((nBytes = fin.read(bytes)) != -1) {
out.write(bytes, 0, nBytes);
}
out.flush();
Please help...

Reply With Quote

