diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 3ef7cd913f..444b52b88b 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -116,7 +116,11 @@ public class AndroidUtils { } public static Uri getUriForFile(Context context, File file) { - return FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + return Uri.fromFile(file); + } else { + return FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file); + } } public static Spannable replaceCharsWithIcon(String text, Drawable icon, String[] chars) { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 13376edd5b..02a006c272 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -3,6 +3,7 @@ package net.osmand.plus.audionotes; import android.Manifest; import android.annotation.TargetApi; import android.app.Activity; +import android.content.ClipData; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; @@ -828,6 +829,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public void captureImage(double lat, double lon, final MapActivity mapActivity) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri fileUri = AndroidUtils.getUriForFile(mapActivity, getBaseFileName(lat, lon, app, IMG_EXTENSION)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) { + intent.setClipData(ClipData.newRawUri("", fileUri)); + } intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // start the image capture Intent @@ -842,8 +846,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { // ext = THREEGP_EXTENSION; // } Uri fileUri = AndroidUtils.getUriForFile(mapActivity, getBaseFileName(lat, lon, app, ext)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) { + intent.setClipData(ClipData.newRawUri("", fileUri)); + } intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high // start the video capture Intent mapActivity.startActivityForResult(intent, 205); @@ -1502,8 +1509,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); final File f = getBaseFileName(lat, lon, app, IMG_EXTENSION); lastTakingPhoto = f; - takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, AndroidUtils.getUriForFile(mapActivity,f)); - takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + Uri uri = AndroidUtils.getUriForFile(mapActivity, f); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) { + takePictureIntent.setClipData(ClipData.newRawUri("", uri)); + } + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); + takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); try { mapActivity.startActivityForResult(takePictureIntent, 205); } catch (Exception e) {