From b712656968b82a69d436a1c25a6a5ec17dac164e Mon Sep 17 00:00:00 2001 From: Federico Iosue Date: Wed, 24 Jul 2019 23:50:11 +0200 Subject: [PATCH] Implemented FileProvider to get pictures and videos by camera --- gradle.properties | 3 +-- omniNotes/src/main/AndroidManifest.xml | 10 ++++++++++ .../java/it/feio/android/omninotes/DetailFragment.java | 7 ++++--- .../it/feio/android/omninotes/utils/StorageHelper.java | 6 ++++++ omniNotes/src/main/res/raw/changelog.xml | 1 + omniNotes/src/main/res/xml/file_provider_paths.xml | 5 +++++ 6 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 omniNotes/src/main/res/xml/file_provider_paths.xml diff --git a/gradle.properties b/gradle.properties index baa91237e5..2eaff2298b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,11 +16,10 @@ # VERSION_NAME=5.5.3 -VERSION_CODE=260 +VERSION_CODE=261 PACKAGE=it.feio.android.omninotes MIN_SDK=16 -# Upgrading this to 24+ will need ContentProvider for sharing and camera attachments TARGET_SDK=26 BUILD_TOOLS=27.0.3 diff --git a/omniNotes/src/main/AndroidManifest.xml b/omniNotes/src/main/AndroidManifest.xml index 7a70fd97cb..dc839743ec 100644 --- a/omniNotes/src/main/AndroidManifest.xml +++ b/omniNotes/src/main/AndroidManifest.xml @@ -300,6 +300,16 @@ android:value="1" /> + + + + 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 3eb8d6e148..4d9de5c0c0 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java @@ -1301,8 +1301,8 @@ private void takePhoto() { mainActivity.showMessage(R.string.error, ONStyle.ALERT); return; } - // Launches intent - attachmentUri = Uri.fromFile(f); + attachmentUri = StorageHelper.getFileProvider(f); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri); startActivityForResult(intent, TAKE_PHOTO); } @@ -1320,7 +1320,8 @@ private void takeVideo() { mainActivity.showMessage(R.string.error, ONStyle.ALERT); return; } - attachmentUri = Uri.fromFile(f); + attachmentUri = StorageHelper.getFileProvider(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", ""); diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/StorageHelper.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/StorageHelper.java index 652d83e38e..0a22087238 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/StorageHelper.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/StorageHelper.java @@ -24,10 +24,13 @@ import android.os.Environment; import android.os.StatFs; import android.provider.MediaStore; +import android.support.v4.content.FileProvider; import android.text.TextUtils; import android.util.Log; import android.webkit.MimeTypeMap; import android.widget.Toast; + +import it.feio.android.omninotes.OmniNotes; import it.feio.android.omninotes.R; import it.feio.android.omninotes.models.Attachment; import org.apache.commons.io.FileUtils; @@ -546,4 +549,7 @@ public static File getFromHttp(String url, File file) throws IOException { } + public static Uri getFileProvider(File file) { + return FileProvider.getUriForFile(OmniNotes.getAppContext(), OmniNotes.getAppContext().getPackageName() + ".authority", file); + } } diff --git a/omniNotes/src/main/res/raw/changelog.xml b/omniNotes/src/main/res/raw/changelog.xml index 396bbc5348..edce604380 100644 --- a/omniNotes/src/main/res/raw/changelog.xml +++ b/omniNotes/src/main/res/raw/changelog.xml @@ -18,6 +18,7 @@ + [u]Fix[/u] Taking pictures from camera [u]Fix[/u] Fixed backup/restore on Android Pie diff --git a/omniNotes/src/main/res/xml/file_provider_paths.xml b/omniNotes/src/main/res/xml/file_provider_paths.xml new file mode 100644 index 0000000000..abda59e59d --- /dev/null +++ b/omniNotes/src/main/res/xml/file_provider_paths.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file