mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-28 12:47:43 +00:00
Fixed bug retrieving incorrect file sizes for file transfers
For some reason querying the content provider returns a different size than using File.length()
This commit is contained in:
parent
3c10312d15
commit
6aa49757fc
@ -180,6 +180,9 @@ public class ShareToReceiver extends ActionBarActivity {
|
|||||||
|
|
||||||
if (uri.getScheme().equals("file")) {
|
if (uri.getScheme().equals("file")) {
|
||||||
// file:// is a non media uri, so we cannot query the ContentProvider
|
// file:// is a non media uri, so we cannot query the ContentProvider
|
||||||
|
|
||||||
|
np.set("filename", uri.getLastPathSegment());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
size = (int)new File(uri.getPath()).length();
|
size = (int)new File(uri.getPath()).length();
|
||||||
np.setPayload(inputStream, size);
|
np.setPayload(inputStream, size);
|
||||||
@ -187,35 +190,23 @@ public class ShareToReceiver extends ActionBarActivity {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e("ShareToReceiver", "Could not obtain file size");
|
Log.e("ShareToReceiver", "Could not obtain file size");
|
||||||
}
|
}
|
||||||
try{
|
|
||||||
np.set("filename", uri.getLastPathSegment());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.e("ShareToReceiver", "Could not obtain file name");
|
|
||||||
}
|
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
// Probably a content:// uri, so we query the Media content provider
|
// Probably a content:// uri, so we query the Media content provider
|
||||||
String[] proj = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.SIZE, MediaStore.MediaColumns.DISPLAY_NAME };
|
|
||||||
Cursor cursor = managedQuery(uri, proj, null, null, null);
|
|
||||||
try {
|
|
||||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE);
|
|
||||||
cursor.moveToFirst();
|
|
||||||
size = cursor.getInt(column_index);
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.e("ShareToReceiver", "Could not obtain file size");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Log.e("ShareToReceiver", "Size "+size);
|
|
||||||
np.setPayload(inputStream, size);
|
|
||||||
|
|
||||||
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
|
String[] proj = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.SIZE, MediaStore.MediaColumns.DISPLAY_NAME };
|
||||||
|
cursor = getContentResolver().query(uri, proj, null, null, null);
|
||||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
String path = cursor.getString(column_index);
|
String path = cursor.getString(column_index);
|
||||||
np.set("filename", Uri.parse(path).getLastPathSegment());
|
np.set("filename", Uri.parse(path).getLastPathSegment());
|
||||||
|
np.set("size", (int)new File(path).length());
|
||||||
} catch(Exception _) {
|
} catch(Exception _) {
|
||||||
|
|
||||||
|
Log.e("ShareToReceiver", "Could not resolve media to a file, trying to get info as media");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME);
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME);
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
@ -225,9 +216,22 @@ public class ShareToReceiver extends ActionBarActivity {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e("ShareToReceiver", "Could not obtain file name");
|
Log.e("ShareToReceiver", "Could not obtain file name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
//For some reason this size can differ from the actual file size!
|
||||||
|
size = cursor.getInt(column_index);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.e("ShareToReceiver", "Could not obtain file size");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.close();
|
np.setPayload(inputStream, size);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
device.sendPackage(np, new Device.SendPackageFinishedCallback() {
|
device.sendPackage(np, new Device.SendPackageFinishedCallback() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user