private int sendFile(BluetoothOppSendFileInfo fileInfo) {
boolean error = false;
int responseCode = -1;
- int position = 0;
+ long position = 0;
int status = BluetoothShare.STATUS_SUCCESS;
Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + mInfo.mId);
ContentValues updateValues;
if (!error) {
int readLength = 0;
+ long percent = 0;
+ long prevPercent = 0;
boolean okToProceed = false;
long timestamp = 0;
int outputBufferSize = putOperation.getMaxPacketSize();
+ " readLength " + readLength + " bytes took "
+ (System.currentTimeMillis() - timestamp) + " ms");
}
- updateValues = new ContentValues();
- updateValues.put(BluetoothShare.CURRENT_BYTES, position);
- mContext1.getContentResolver().update(contentUri, updateValues,
- null, null);
+ // Update the Progress Bar only if there is change in percentage
+ percent = position * 100 / fileInfo.mLength;
+ if (percent > prevPercent) {
+ updateValues = new ContentValues();
+ updateValues.put(BluetoothShare.CURRENT_BYTES, position);
+ mContext1.getContentResolver().update(contentUri, updateValues,
+ null, null);
+ prevPercent = percent;
+ }
}
}
}
mContext.getContentResolver().update(contentUri, updateValues, null, null);
}
- int position = 0;
+ long position = 0;
+ long percent = 0;
+ long prevPercent = 0;
+
if (!error) {
bos = new BufferedOutputStream(fileInfo.mOutputStream, 0x10000);
}
bos.write(b, 0, readLength);
position += readLength;
+ percent = position * 100 / fileInfo.mLength;
if (V) {
Log.v(TAG, "Receive file position = " + position + " readLength "
+ (System.currentTimeMillis() - timestamp) + " ms");
}
- ContentValues updateValues = new ContentValues();
- updateValues.put(BluetoothShare.CURRENT_BYTES, position);
- mContext.getContentResolver().update(contentUri, updateValues, null, null);
+ // Update the Progress Bar only if there is change in percentage
+ if (percent > prevPercent) {
+ ContentValues updateValues = new ContentValues();
+ updateValues.put(BluetoothShare.CURRENT_BYTES, position);
+ mContext.getContentResolver().update(contentUri, updateValues, null, null);
+ prevPercent = percent;
+ }
}
} catch (IOException e1) {
Log.e(TAG, "Error when receiving file");