Skip to content

Commit b712656

Browse files
committed
Implemented FileProvider to get pictures and videos by camera
1 parent 0bf302f commit b712656

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
#
1717

1818
VERSION_NAME=5.5.3
19-
VERSION_CODE=260
19+
VERSION_CODE=261
2020
PACKAGE=it.feio.android.omninotes
2121

2222
MIN_SDK=16
23-
# Upgrading this to 24+ will need ContentProvider for sharing and camera attachments
2423
TARGET_SDK=26
2524
BUILD_TOOLS=27.0.3
2625

omniNotes/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,16 @@
300300
android:value="1" />
301301
</service>
302302

303+
<provider
304+
android:name="android.support.v4.content.FileProvider"
305+
android:authorities="${applicationId}.authority"
306+
android:exported="false"
307+
android:grantUriPermissions="true">
308+
<meta-data
309+
android:name="android.support.FILE_PROVIDER_PATHS"
310+
android:resource="@xml/file_provider_paths" />
311+
</provider>
312+
303313
</application>
304314

305315
</manifest>

omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,8 @@ private void takePhoto() {
13011301
mainActivity.showMessage(R.string.error, ONStyle.ALERT);
13021302
return;
13031303
}
1304-
// Launches intent
1305-
attachmentUri = Uri.fromFile(f);
1304+
attachmentUri = StorageHelper.getFileProvider(f);
1305+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
13061306
intent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
13071307
startActivityForResult(intent, TAKE_PHOTO);
13081308
}
@@ -1320,7 +1320,8 @@ private void takeVideo() {
13201320
mainActivity.showMessage(R.string.error, ONStyle.ALERT);
13211321
return;
13221322
}
1323-
attachmentUri = Uri.fromFile(f);
1323+
attachmentUri = StorageHelper.getFileProvider(f);
1324+
takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
13241325
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
13251326
String maxVideoSizeStr = "".equals(prefs.getString("settings_max_video_size",
13261327
"")) ? "0" : prefs.getString("settings_max_video_size", "");

omniNotes/src/main/java/it/feio/android/omninotes/utils/StorageHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
import android.os.Environment;
2525
import android.os.StatFs;
2626
import android.provider.MediaStore;
27+
import android.support.v4.content.FileProvider;
2728
import android.text.TextUtils;
2829
import android.util.Log;
2930
import android.webkit.MimeTypeMap;
3031
import android.widget.Toast;
32+
33+
import it.feio.android.omninotes.OmniNotes;
3134
import it.feio.android.omninotes.R;
3235
import it.feio.android.omninotes.models.Attachment;
3336
import org.apache.commons.io.FileUtils;
@@ -546,4 +549,7 @@ public static File getFromHttp(String url, File file) throws IOException {
546549
}
547550

548551

552+
public static Uri getFileProvider(File file) {
553+
return FileProvider.getUriForFile(OmniNotes.getAppContext(), OmniNotes.getAppContext().getPackageName() + ".authority", file);
554+
}
549555
}

omniNotes/src/main/res/raw/changelog.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<changelog bulletedList="true">
1919

2020
<changelogversion versionName="5.5.3" changeDate="Jul 23, 2019">
21+
<changelogtext>[u]Fix[/u] Taking pictures from camera</changelogtext>
2122
<changelogtext>[u]Fix[/u] Fixed backup/restore on Android Pie</changelogtext>
2223
</changelogversion>
2324

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<paths>
3+
<external-path
4+
name="external_files" path="." />
5+
</paths>

0 commit comments

Comments
 (0)