diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 1ee5191db..0648aaa62 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -186,11 +186,6 @@ public class FileBackend { return paint; } - private static String getTakePhotoPath() { - return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) - + "/Camera/"; - } - public static Uri getUriForUri(Context context, Uri uri) { if ("file".equals(uri.getScheme())) { return getUriForFile(context, new File(uri.getPath())); @@ -474,19 +469,6 @@ public class FileBackend { return bitmap; } - private void createNoMedia(File diretory) { - final File noMedia = new File(diretory, ".nomedia"); - if (!noMedia.exists()) { - try { - if (!noMedia.createNewFile()) { - Log.d(Config.LOGTAG, "created nomedia file " + noMedia.getAbsolutePath()); - } - } catch (Exception e) { - Log.d(Config.LOGTAG, "could not create nomedia file"); - } - } - } - public void updateMediaScanner(File file) { updateMediaScanner(file, null); } @@ -724,28 +706,18 @@ public class FileBackend { copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri); } - private String getExtensionFromUri(Uri uri) { - String[] projection = {MediaStore.MediaColumns.DATA}; + private String getExtensionFromUri(final Uri uri) { + final String[] projection = {MediaStore.MediaColumns.DATA}; String filename = null; - Cursor cursor; - try { - cursor = - mXmppConnectionService - .getContentResolver() - .query(uri, projection, null, null, null); - } catch (IllegalArgumentException e) { - cursor = null; - } - if (cursor != null) { - try { - if (cursor.moveToFirst()) { - filename = cursor.getString(0); - } - } catch (Exception e) { - filename = null; - } finally { - cursor.close(); + try (final Cursor cursor = + mXmppConnectionService + .getContentResolver() + .query(uri, projection, null, null, null)) { + if (cursor != null && cursor.moveToFirst()) { + filename = cursor.getString(0); } + } catch (final SecurityException | IllegalArgumentException e) { + filename = null; } if (filename == null) { final List segments = uri.getPathSegments(); @@ -753,7 +725,7 @@ public class FileBackend { filename = segments.get(segments.size() - 1); } } - int pos = filename == null ? -1 : filename.lastIndexOf('.'); + final int pos = filename == null ? -1 : filename.lastIndexOf('.'); return pos > 0 ? filename.substring(pos + 1) : null; }