2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 13:47:41 +00:00

Clean up uriToNetworkPacket

- Remove redundant code
- Make top-level block function properly
This commit is contained in:
Simon Redman
2019-04-02 17:53:00 -06:00
parent a3fb423dd3
commit 177c18e0f4

View File

@@ -134,44 +134,23 @@ public class FilesHelper {
} 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.SIZE,
MediaStore.MediaColumns.DISPLAY_NAME,
};
Cursor cursor = null; try (Cursor cursor = cr.query(uri, proj, null, null, null)) {
try { int nameColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME);
String[] proj = {MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.SIZE, MediaStore.MediaColumns.DISPLAY_NAME}; int sizeColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE);
cursor = cr.query(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
cursor.moveToFirst(); cursor.moveToFirst();
String path = cursor.getString(column_index);
np.set("filename", Uri.parse(path).getLastPathSegment());
size = new File(path).length();
} catch (Exception unused) {
Log.w("SendFileActivity", "Could not resolve media to a file, trying to get info as media"); String filename = cursor.getString(nameColumnIndex);
size = cursor.getInt(sizeColumnIndex);
try { np.set("filename", filename);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME); } catch (Exception e) {
cursor.moveToFirst(); Log.e("SendFileActivity", "Problem getting file information", e);
String name = cursor.getString(column_index);
np.set("filename", name);
} catch (Exception e) {
Log.e("SendFileActivity", "Could not obtain file name", e);
}
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) {
Log.e("SendFileActivity", "Could not obtain file size", e);
}
} finally {
try {
cursor.close();
} catch (Exception ignored) {
}
} }
} }
np.setPayload(new NetworkPacket.Payload(inputStream, size)); np.setPayload(new NetworkPacket.Payload(inputStream, size));