Skip to content

Commit

Permalink
Implemented FileProvider to get pictures and videos by camera
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Jul 24, 2019
1 parent 0bf302f commit b712656
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions omniNotes/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@
android:value="1" />
</service>

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.authority"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions omniNotes/src/main/res/raw/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<changelog bulletedList="true">

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

Expand Down
5 changes: 5 additions & 0 deletions omniNotes/src/main/res/xml/file_provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external_files" path="." />
</paths>

0 comments on commit b712656

Please sign in to comment.