From 6fb465f91aae23db422ff2ab9277ec6b0f94a57b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 22 Feb 2022 16:23:51 +0100 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20query=20packages=20before=20att?= =?UTF-8?q?aching=20something?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../conversations/persistance/FileBackend.java | 14 ++++---------- .../conversations/ui/ConversationFragment.java | 5 +++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 505a3ebb5..c36011577 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -1147,19 +1147,13 @@ public class FileBackend { } public Uri getTakePhotoUri() { + final String filename = String.format("IMG_%s.%s", IMAGE_DATE_FORMAT.format(new Date()),"jpg"); File file; if (Config.ONLY_INTERNAL_STORAGE) { - file = - new File( - mXmppConnectionService.getCacheDir().getAbsolutePath(), - "Camera/IMG_" + IMAGE_DATE_FORMAT.format(new Date()) + ".jpg"); + final File dcimCache = new File(mXmppConnectionService.getCacheDir(), "Camera"); + file = new File(dcimCache, filename); } else { - file = - new File( - getTakePhotoPath() - + "IMG_" - + IMAGE_DATE_FORMAT.format(new Date()) - + ".jpg"); + file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), filename); } file.getParentFile().mkdirs(); return getUriForFile(mXmppConnectionService, file); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index b7215c22d..a42fa6766 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -6,6 +6,7 @@ import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.app.PendingIntent; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -1744,7 +1745,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (context == null) { return; } - if (intent.resolveActivity(context.getPackageManager()) != null) { + try { if (chooser) { startActivityForResult( Intent.createChooser(intent, getString(R.string.perform_action_with)), @@ -1752,7 +1753,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } else { startActivityForResult(intent, attachmentChoice); } - } else { + } catch (final ActivityNotFoundException e) { Toast.makeText(context, R.string.no_application_found, Toast.LENGTH_LONG).show(); } }