diff --git a/gradle.properties b/gradle.properties
index f2a933a74..762ea8030 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -14,8 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-VERSION_NAME=6.2.3
-VERSION_CODE=318
+VERSION_NAME=6.2.4
+VERSION_CODE=319
PACKAGE=it.feio.android.omninotes
MIN_SDK=21
TARGET_SDK=31
diff --git a/omniNotes/src/androidTest/java/it/feio/android/omninotes/testutils/BaseAndroidTestCase.java b/omniNotes/src/androidTest/java/it/feio/android/omninotes/testutils/BaseAndroidTestCase.java
index b34c15342..d34837364 100644
--- a/omniNotes/src/androidTest/java/it/feio/android/omninotes/testutils/BaseAndroidTestCase.java
+++ b/omniNotes/src/androidTest/java/it/feio/android/omninotes/testutils/BaseAndroidTestCase.java
@@ -129,7 +129,7 @@ protected Note createTestNote(String title, String content, int attachmentsNumbe
return note;
}
- private Attachment createTestAttachment(String attachmentName) {
+ protected Attachment createTestAttachment(String attachmentName) {
try {
File testAttachment = File.createTempFile(attachmentName, ".txt");
IOUtils.write(
diff --git a/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/FileProviderHelperTest.kt b/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/FileProviderHelperTest.kt
new file mode 100644
index 000000000..f8e4c4883
--- /dev/null
+++ b/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/FileProviderHelperTest.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2013-2023 Federico Iosue (federico@iosue.it)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package it.feio.android.omninotes.utils
+
+
+import android.net.Uri
+import androidx.core.net.toUri
+import it.feio.android.omninotes.OmniNotes.getAppContext
+import it.feio.android.omninotes.models.Attachment
+import it.feio.android.omninotes.testutils.BaseAndroidTestCase
+import it.feio.android.omninotes.utils.ConstantsBase.MIME_TYPE_IMAGE
+import org.junit.Assert.*
+import org.junit.Test
+import java.io.File
+
+class FileProviderHelperTest : BaseAndroidTestCase() {
+
+ @Test
+ fun getShareableUri() {
+ val file = File("/storage/emulated/0/Android/data/it.feio.android.omninotes/files/424242.png")
+ assertTrue(file.createNewFile() || file.exists())
+ val attachment = Attachment(file.toUri(), MIME_TYPE_IMAGE)
+
+ val res = FileProviderHelper.getShareableUri(attachment)
+
+ assertNotNull(res)
+ assertNotEquals(file.toUri(), res)
+ assertTrue(res?.scheme.equals("content") && res?.authority.equals(getAppContext().packageName + ".authority"))
+
+ file.deleteOnExit()
+ }
+
+ @Test
+ fun getShareableUri_contentScheme() {
+ val uri = "content://it.feio.android.omninotes.authority/external_files/Android/data/it.feio.android.omninotes/files/20230418_091959_730.jpeg"
+ val attachment = Attachment(Uri.parse(uri), "")
+
+ val res = FileProviderHelper.getShareableUri(attachment)
+
+ assertEquals(uri, res)
+ }
+
+}
\ No newline at end of file
diff --git a/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/IntentCheckerTest.kt b/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/IntentCheckerTest.kt
new file mode 100644
index 000000000..6692ac8d6
--- /dev/null
+++ b/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/IntentCheckerTest.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013-2023 Federico Iosue (federico@iosue.it)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package it.feio.android.omninotes.utils;
+
+import android.content.Intent
+import android.provider.MediaStore.ACTION_IMAGE_CAPTURE
+import it.feio.android.omninotes.testutils.BaseAndroidTestCase
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+
+class IntentCheckerTest : BaseAndroidTestCase() {
+
+ @Test
+ fun resolveActivityPackage() {
+ val res = IntentChecker.resolveActivityPackage(testContext, Intent(ACTION_IMAGE_CAPTURE))
+ assertTrue(res.isNotEmpty())
+ }
+
+}
\ No newline at end of file
diff --git a/omniNotes/src/main/AndroidManifest.xml b/omniNotes/src/main/AndroidManifest.xml
index 9238a512a..4dfce72db 100644
--- a/omniNotes/src/main/AndroidManifest.xml
+++ b/omniNotes/src/main/AndroidManifest.xml
@@ -337,6 +337,9 @@
+
+
+
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java b/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java
index 3a76144c0..eba4de4a5 100644
--- a/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java
@@ -18,6 +18,7 @@
import static android.content.Context.CLIPBOARD_SERVICE;
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
+import static android.content.pm.PackageManager.FEATURE_CAMERA;
import static androidx.core.view.ViewCompat.animate;
import static it.feio.android.omninotes.BaseActivity.TRANSITION_HORIZONTAL;
import static it.feio.android.omninotes.BaseActivity.TRANSITION_VERTICAL;
@@ -1290,12 +1291,9 @@ private void showAttachmentsPopup() {
}
private void takePhoto() {
- // Checks for camera app available
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- if (!IntentChecker
- .isAvailable(mainActivity, intent, new String[]{PackageManager.FEATURE_CAMERA})) {
+ if (!IntentChecker.isAvailable(mainActivity, intent, new String[]{FEATURE_CAMERA})) {
mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);
-
return;
}
// Checks for created file validity
@@ -1304,18 +1302,16 @@ private void takePhoto() {
mainActivity.showMessage(R.string.error, ONStyle.ALERT);
return;
}
- attachmentUri = FileProviderHelper.getFileProvider(f);
+ attachmentUri = Uri.fromFile(f);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
+ intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProviderHelper.getFileProvider(f));
startActivityForResult(intent, TAKE_PHOTO);
}
private void takeVideo() {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
- if (!IntentChecker
- .isAvailable(mainActivity, takeVideoIntent, new String[]{PackageManager.FEATURE_CAMERA})) {
+ if (!IntentChecker.isAvailable(mainActivity, takeVideoIntent, new String[]{FEATURE_CAMERA})) {
mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);
-
return;
}
// File is stored in custom ON folder to speedup the attachment
@@ -1324,18 +1320,17 @@ private void takeVideo() {
mainActivity.showMessage(R.string.error, ONStyle.ALERT);
return;
}
- attachmentUri = FileProviderHelper.getFileProvider(f);
+ attachmentUri = Uri.fromFile(f);
takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
- String maxVideoSizeStr = "".equals(Prefs.getString("settings_max_video_size",
- "")) ? "0" : Prefs.getString("settings_max_video_size", "");
+ takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProviderHelper.getFileProvider(f));
+ String maxVideoSizeStr = "".equals(Prefs.getString("settings_max_video_size", ""))
+ ? "0" : Prefs.getString("settings_max_video_size", "");
long maxVideoSize = parseLong(maxVideoSizeStr) * 1024L * 1024L;
takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, maxVideoSize);
startActivityForResult(takeVideoIntent, TAKE_VIDEO);
}
private void takeSketch(Attachment attachment) {
-
File f = StorageHelper.createNewAttachmentFile(mainActivity, MIME_TYPE_SKETCH_EXT);
if (f == null) {
mainActivity.showMessage(R.string.error, ONStyle.ALERT);
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/async/DataBackupIntentService.java b/omniNotes/src/main/java/it/feio/android/omninotes/async/DataBackupIntentService.java
index 39f40d0ef..5a44c4172 100644
--- a/omniNotes/src/main/java/it/feio/android/omninotes/async/DataBackupIntentService.java
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/async/DataBackupIntentService.java
@@ -101,7 +101,9 @@ private void exportData(Intent intent) {
BackupHelper.exportNotes(backupDir);
BackupHelper.exportAttachments(backupDir, mNotificationsHelper);
- mNotificationsHelper.finish(getString(R.string.data_export_completed), backupDir.getUri().getPath());
+
+ var readableBackupFolder = BackupHelper.getBackupFolderPath() + "/" + backupName;
+ mNotificationsHelper.finish(getString(R.string.data_export_completed), readableBackupFolder);
}
@TargetApi(VERSION_CODES.O)
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/FileHelper.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/FileHelper.java
index 3c01be26e..0a8fe0a71 100644
--- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/FileHelper.java
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/FileHelper.java
@@ -29,14 +29,12 @@
import it.feio.android.omninotes.factory.MediaStoreFactory;
import it.feio.android.omninotes.helpers.LogDelegate;
import java.io.File;
+import lombok.experimental.UtilityClass;
+@UtilityClass
public class FileHelper {
- private FileHelper() {
- // hides public constructor
- }
-
/**
* Get a file path from a Uri. This will get the the path for Storage Access Framework Documents,
* as well as the _data field for the MediaStore and other file-based ContentProviders.
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/FileProviderHelper.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/FileProviderHelper.java
index 5ce5c7a19..7178d594d 100644
--- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/FileProviderHelper.java
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/FileProviderHelper.java
@@ -17,37 +17,42 @@
package it.feio.android.omninotes.utils;
+import static androidx.core.content.FileProvider.getUriForFile;
+import static it.feio.android.omninotes.OmniNotes.getAppContext;
+
import android.net.Uri;
import androidx.annotation.Nullable;
-import androidx.core.content.FileProvider;
-import it.feio.android.omninotes.OmniNotes;
import it.feio.android.omninotes.models.Attachment;
import java.io.File;
import java.io.FileNotFoundException;
+import lombok.experimental.UtilityClass;
+@UtilityClass
public class FileProviderHelper {
- private FileProviderHelper() {
- // hides public constructor
- }
-
/**
* Generates the FileProvider URI for a given existing file
*/
public static Uri getFileProvider(File file) {
- return FileProvider.getUriForFile(OmniNotes.getAppContext(),
- OmniNotes.getAppContext().getPackageName() + ".authority", file);
+ return getUriForFile(getAppContext(), getAppContext().getPackageName() + ".authority", file);
}
/**
* Generates a shareable URI for a given attachment by evaluating its stored (into DB) path
*/
public static @Nullable Uri getShareableUri(Attachment attachment) throws FileNotFoundException {
- File attachmentFile = new File(attachment.getUri().getPath());
+ var uri = attachment.getUri();
+
+ if (uri.getScheme().equals("content")
+ && uri.getAuthority().equals(getAppContext().getPackageName() + ".authority")) {
+ return uri;
+ }
+
+ File attachmentFile = new File(uri.getPath());
if (!attachmentFile.exists()) {
throw new FileNotFoundException("Required attachment not found in " + attachment.getUriPath());
}
- return FileProviderHelper.getFileProvider(attachmentFile);
+ return getFileProvider(attachmentFile);
}
}
diff --git a/omniNotes/src/main/res/raw/changelog.xml b/omniNotes/src/main/res/raw/changelog.xml
index 704754819..8d77aded8 100644
--- a/omniNotes/src/main/res/raw/changelog.xml
+++ b/omniNotes/src/main/res/raw/changelog.xml
@@ -16,6 +16,12 @@
-->
+
+ [u]Fix[/u] Take camera picture action from some devices
+
+