From 1f209acf287c60949d9869850b0dfa54bac91d11 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 21 May 2018 11:45:21 +0300 Subject: [PATCH 1/6] fix FileUriExposedException --- .../net/osmand/plus/audionotes/AudioVideoNotesPlugin.java | 5 +++-- .../src/net/osmand/plus/myplaces/AvailableGPXFragment.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index ee283f50ca..4b7c95918d 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -25,6 +25,7 @@ import android.os.StatFs; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; +import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; import android.view.Display; import android.view.KeyEvent; @@ -1878,7 +1879,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public void playRecording(final Context ctx, final Recording r) { if (r.isVideo()) { Intent vint = new Intent(Intent.ACTION_VIEW); - vint.setDataAndType(Uri.fromFile(r.file), "video/*"); + vint.setDataAndType(FileProvider.getUriForFile(mapActivity,"net.osmand.plus.fileprovider",r.file), "video/*"); vint.setFlags(0x10000000); try { ctx.startActivity(vint); @@ -1888,7 +1889,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { return; } else if (r.isPhoto()) { Intent vint = new Intent(Intent.ACTION_VIEW); - vint.setDataAndType(Uri.fromFile(r.file), "image/*"); + vint.setDataAndType(FileProvider.getUriForFile(mapActivity,"net.osmand.plus.fileprovider",r.file), "image/*"); vint.setFlags(0x10000000); ctx.startActivity(vint); return; diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 8ac0cace80..207ebe5c97 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -15,6 +15,7 @@ import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; +import android.support.v4.content.FileProvider; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; @@ -1410,7 +1411,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - final Uri fileUri = Uri.fromFile(gpxInfo.file); + final Uri fileUri = FileProvider.getUriForFile(getMyApplication(),"net.osmand.plus.fileprovider", gpxInfo.file); final Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.setType("application/gpx+xml"); From d5722ded0cf0fcd59688fea9c355471e777c02bc Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 21 May 2018 11:48:54 +0300 Subject: [PATCH 2/6] fix NPE --- .../src/net/osmand/plus/download/ui/LocalIndexesFragment.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index 4c11d9f79d..256db522a8 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -595,7 +595,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement @Override public void onDestroy() { super.onDestroy(); - asyncLoader.cancel(true); + if (asyncLoader != null && asyncLoader.getStatus() == AsyncTask.Status.RUNNING) { + asyncLoader.cancel(true); + } } From 730c394ac5790709c2e73b7efa3c3d997c546669 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 21 May 2018 11:56:08 +0300 Subject: [PATCH 3/6] fix authority --- .../src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java | 4 ++-- OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 4b7c95918d..538078ca55 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -1879,7 +1879,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public void playRecording(final Context ctx, final Recording r) { if (r.isVideo()) { Intent vint = new Intent(Intent.ACTION_VIEW); - vint.setDataAndType(FileProvider.getUriForFile(mapActivity,"net.osmand.plus.fileprovider",r.file), "video/*"); + vint.setDataAndType(FileProvider.getUriForFile(mapActivity,mapActivity.getPackageName() + ".fileprovider",r.file), "video/*"); vint.setFlags(0x10000000); try { ctx.startActivity(vint); @@ -1889,7 +1889,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { return; } else if (r.isPhoto()) { Intent vint = new Intent(Intent.ACTION_VIEW); - vint.setDataAndType(FileProvider.getUriForFile(mapActivity,"net.osmand.plus.fileprovider",r.file), "image/*"); + vint.setDataAndType(FileProvider.getUriForFile(mapActivity,mapActivity.getPackageName() + ".fileprovider",r.file), "image/*"); vint.setFlags(0x10000000); ctx.startActivity(vint); return; diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 207ebe5c97..6f82b84b4a 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -1411,7 +1411,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - final Uri fileUri = FileProvider.getUriForFile(getMyApplication(),"net.osmand.plus.fileprovider", gpxInfo.file); + final Uri fileUri = FileProvider.getUriForFile(getMyApplication(),getActivity().getPackageName() + ".fileprovider", gpxInfo.file); final Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.setType("application/gpx+xml"); From 625802e4435ac4746b279c66744e99d397363dad Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 21 May 2018 14:06:19 +0300 Subject: [PATCH 4/6] change Uri.fromFile to FileProvider.getUriForFile --- .../plus/activities/ContributionVersionActivity.java | 7 ++++--- .../plus/activities/ShowRouteInfoDialogFragment.java | 6 ++++-- .../osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java | 5 +++-- .../net/osmand/plus/audionotes/AudioVideoNotesPlugin.java | 8 +++++--- OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java | 2 +- .../src/net/osmand/plus/dashboard/DashErrorFragment.java | 5 +++-- .../net/osmand/plus/dialogs/ErrorBottomSheetDialog.java | 6 +++--- .../src/net/osmand/plus/myplaces/TrackPointFragment.java | 4 +++- .../net/osmand/plus/myplaces/TrackSegmentFragment.java | 4 +++- OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java | 5 +++-- 10 files changed, 32 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java index f12f445ed7..3f0ae5f206 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java @@ -3,8 +3,8 @@ package net.osmand.plus.activities; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; -import android.net.Uri; import android.os.Bundle; +import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; @@ -111,8 +111,9 @@ public class ContributionVersionActivity extends OsmandListActivity { if(currentSelectedBuild != null){ Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setDataAndType(Uri.fromFile(pathToDownload), "application/vnd.android.package-archive"); - startActivityForResult(intent, ACTIVITY_TO_INSTALL); + intent.setDataAndType(FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",pathToDownload), "application/vnd.android.package-archive"); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startActivityForResult(intent, ACTIVITY_TO_INSTALL); updateInstalledApp(false, currentSelectedBuild.date); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java index 599d867829..ed6dd73f5c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java @@ -440,7 +440,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { @Override public void onClick(View v) { final GPXFile gpx = helper.generateGPXFileWithRoute(); - final Uri fileUri = Uri.fromFile(new File(gpx.path)); + final Uri fileUri = FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",new File(gpx.path)); File dir = new File(getActivity().getCacheDir(), "share"); if (!dir.exists()) { dir.mkdir(); @@ -461,6 +461,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { FileProvider.getUriForFile(getActivity(), getActivity().getPackageName() + ".fileprovider", dst)); sendIntent.setType("text/plain"); + sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(sendIntent); } catch (IOException e) { // Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), @@ -560,7 +561,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { void print() { File file = generateRouteInfoHtml(adapter, helper.getGeneralRouteInformation()); if (file.exists()) { - Uri uri = Uri.fromFile(file); + Uri uri = FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",file); Intent browserIntent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // use Android Print Framework browserIntent = new Intent(getActivity(), PrintDialogActivity.class) @@ -569,6 +570,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { browserIntent = new Intent(Intent.ACTION_VIEW).setDataAndType( uri, "text/html"); } + browserIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(browserIntent); } } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java index b241fbb808..49830400ec 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java @@ -4,7 +4,7 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; -import android.net.Uri; +import android.support.v4.content.FileProvider; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; @@ -64,8 +64,9 @@ public class AudioVideoNoteMenuBuilder extends MenuBuilder { @Override public void onClick(View v) { Intent vint = new Intent(Intent.ACTION_VIEW); - vint.setDataAndType(Uri.fromFile(recording.getFile()), "image/*"); + vint.setDataAndType(FileProvider.getUriForFile(getApplication(), getMapActivity().getPackageName() + ".fileprovider", recording.getFile()), "image/*"); vint.setFlags(0x10000000); + vint.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); v.getContext().startActivity(vint); } }); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 538078ca55..3b2226f877 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -828,8 +828,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 = Uri.fromFile(getBaseFileName(lat, lon, app, IMG_EXTENSION)); + Uri fileUri = FileProvider.getUriForFile(getMapActivity(), getMapActivity().getPackageName() + ".fileprovider", (getBaseFileName(lat, lon, app, IMG_EXTENSION))); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // start the image capture Intent mapActivity.startActivityForResult(intent, 105); } @@ -841,7 +842,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { // if (AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP) { // ext = THREEGP_EXTENSION; // } - Uri fileUri = Uri.fromFile(getBaseFileName(lat, lon, app, ext)); + Uri fileUri = FileProvider.getUriForFile(getMapActivity(), getMapActivity().getPackageName() + ".fileprovider", getBaseFileName(lat, lon, app, ext)); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high @@ -1503,7 +1504,8 @@ 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, Uri.fromFile(f)); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getMapActivity(), getMapActivity().getPackageName() + ".fileprovider",f)); + takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { mapActivity.startActivityForResult(takePictureIntent, 205); } catch (Exception e) { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java index 25c023ceaf..6468daaa4f 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java @@ -463,7 +463,7 @@ public class NotesFragment extends OsmAndListFragment { for (Recording rec : selected) { File file = rec == SHARE_LOCATION_FILE ? generateGPXForRecordings(selected) : rec.getFile(); if (file != null) { - uris.add(FileProvider.getUriForFile(getContext(), getActivity().getPackageName() + ".fileprovider", file)); + uris.add(FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider", file)); } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java index 8679cb4e1e..1e4c759cd2 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java @@ -4,10 +4,10 @@ import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.graphics.Typeface; -import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.support.design.widget.Snackbar; +import android.support.v4.content.FileProvider; import android.support.v4.view.ViewCompat; import android.view.LayoutInflater; import android.view.View; @@ -61,7 +61,8 @@ public class DashErrorFragment extends DashBaseFragment { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$ File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH); - intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); + intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",file)); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$ intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$ StringBuilder text = new StringBuilder(); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java index 47bf88e3ae..bfc5881a3a 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java @@ -48,7 +48,8 @@ public class ErrorBottomSheetDialog extends BottomSheetDialogFragment { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$ File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH); - intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getMyApplication(),"net.osmand.plus.fileprovider", file)); + intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider", file)); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$ intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$ StringBuilder text = new StringBuilder(); @@ -89,7 +90,6 @@ public class ErrorBottomSheetDialog extends BottomSheetDialogFragment { } public static boolean shouldShow(OsmandSettings settings, MapActivity activity) { - return activity.getMyApplication().getAppInitializer() - .checkPreviousRunsForExceptions(activity, settings != null); + return true; } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index a27ef0cfd8..9b6afc3ee0 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -13,6 +13,7 @@ import android.support.annotation.Nullable; import android.support.design.widget.Snackbar; import android.support.v4.app.FragmentActivity; import android.support.v4.content.ContextCompat; +import android.support.v4.content.FileProvider; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; @@ -291,10 +292,11 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements private void shareItems() { GPXFile gpxFile = getGpx(); if (gpxFile != null) { - final Uri fileUri = Uri.fromFile(new File(gpxFile.path)); + final Uri fileUri = FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",new File(gpxFile.path)); final Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.setType("application/gpx+xml"); + sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(sendIntent); } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 36769c5392..9eb5bb2dcd 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -11,6 +11,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.content.FileProvider; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewCompat; @@ -151,10 +152,11 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - final Uri fileUri = Uri.fromFile(new File(getGpx().path)); + final Uri fileUri = FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider", new File(getGpx().path)); final Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.setType("application/gpx+xml"); + sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(sendIntent); return true; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index eaef873dac..53f2bc0827 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -4,7 +4,6 @@ import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; -import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; @@ -13,6 +12,7 @@ import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; +import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; import android.util.Xml; @@ -865,8 +865,9 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo final Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_osm_edits_subject)); - sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(osmchange)); + sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider", osmchange)); sendIntent.setType("text/plain"); + sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(sendIntent); } } From 183576066a5d25667af6c80fbb329c53f75c41c6 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 21 May 2018 14:56:28 +0300 Subject: [PATCH 5/6] add AndroidUtils.getUriForFile --- OsmAnd/src/net/osmand/AndroidUtils.java | 6 ++++++ .../plus/activities/ContributionVersionActivity.java | 3 +-- .../osmand/plus/activities/FavoritesTreeFragment.java | 6 ++---- .../plus/activities/ShowRouteInfoDialogFragment.java | 10 ++++------ .../plus/audionotes/AudioVideoNoteMenuBuilder.java | 4 ++-- .../osmand/plus/audionotes/AudioVideoNotesPlugin.java | 11 +++++------ .../src/net/osmand/plus/audionotes/NotesFragment.java | 4 ++-- .../net/osmand/plus/dashboard/DashErrorFragment.java | 4 ++-- .../osmand/plus/dialogs/ErrorBottomSheetDialog.java | 7 ++++--- .../osmand/plus/myplaces/AvailableGPXFragment.java | 3 +-- .../net/osmand/plus/myplaces/TrackPointFragment.java | 3 +-- .../osmand/plus/myplaces/TrackSegmentFragment.java | 3 +-- .../src/net/osmand/plus/osmedit/OsmEditsFragment.java | 4 ++-- .../osmand/plus/search/QuickSearchDialogFragment.java | 5 +---- 14 files changed, 34 insertions(+), 39 deletions(-) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 400b8da648..f1b05985e4 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -12,6 +12,7 @@ import android.graphics.Paint; import android.graphics.PointF; import android.graphics.drawable.Drawable; import android.graphics.drawable.StateListDrawable; +import android.net.Uri; import android.os.Build; import android.os.IBinder; import android.support.annotation.AttrRes; @@ -20,6 +21,7 @@ import android.support.annotation.ColorRes; import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; +import android.support.v4.content.FileProvider; import android.text.Spannable; import android.text.SpannableString; import android.text.TextPaint; @@ -109,6 +111,10 @@ public class AndroidUtils { return src; } + public static Uri getUriForFile(Context context, File file) { + return FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file); + } + public static Spannable replaceCharsWithIcon(String text, Drawable icon, String[] chars) { Spannable spannable = new SpannableString(text); for (String entry : chars) { diff --git a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java index 3f0ae5f206..7941649a9c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java @@ -4,7 +4,6 @@ import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; @@ -111,7 +110,7 @@ public class ContributionVersionActivity extends OsmandListActivity { if(currentSelectedBuild != null){ Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setDataAndType(FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",pathToDownload), "application/vnd.android.package-archive"); + intent.setDataAndType(AndroidUtils.getUriForFile(getMyApplication(), pathToDownload), "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivityForResult(intent, ACTIVITY_TO_INSTALL); updateInstalledApp(false, currentSelectedBuild.date); diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 14ecc5ecb7..b6bc6a9bfd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -12,7 +12,6 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; -import android.support.v4.content.FileProvider; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; @@ -32,6 +31,7 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import net.osmand.AndroidUtils; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -587,9 +587,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { } sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtmlPrint(groups).toString())); sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject)); - sendIntent.putExtra(Intent.EXTRA_STREAM, - FileProvider.getUriForFile(getActivity(), - getActivity().getPackageName() + ".fileprovider", dst)); + sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), dst)); sendIntent.setType("text/plain"); startActivity(sendIntent); } catch (IOException e) { diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java index ed6dd73f5c..abdb4839ce 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java @@ -13,7 +13,6 @@ import android.os.Build; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentManager; -import android.support.v4.content.FileProvider; import android.support.v7.widget.Toolbar; import android.text.Html; import android.text.TextUtils; @@ -35,6 +34,7 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.github.mikephil.charting.listener.ChartTouchListener; import com.github.mikephil.charting.listener.OnChartGestureListener; +import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -440,7 +440,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { @Override public void onClick(View v) { final GPXFile gpx = helper.generateGPXFileWithRoute(); - final Uri fileUri = FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",new File(gpx.path)); + final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), new File(gpx.path)); File dir = new File(getActivity().getCacheDir(), "share"); if (!dir.exists()) { dir.mkdir(); @@ -457,9 +457,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_route_subject)); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.putExtra( - Intent.EXTRA_STREAM, - FileProvider.getUriForFile(getActivity(), - getActivity().getPackageName() + ".fileprovider", dst)); + Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), dst)); sendIntent.setType("text/plain"); sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(sendIntent); @@ -561,7 +559,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { void print() { File file = generateRouteInfoHtml(adapter, helper.getGeneralRouteInformation()); if (file.exists()) { - Uri uri = FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",file); + Uri uri = AndroidUtils.getUriForFile(getMyApplication(), file); Intent browserIntent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // use Android Print Framework browserIntent = new Intent(getActivity(), PrintDialogActivity.class) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java index 49830400ec..26edb25868 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java @@ -4,13 +4,13 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; -import android.support.v4.content.FileProvider; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; +import net.osmand.AndroidUtils; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; @@ -64,7 +64,7 @@ public class AudioVideoNoteMenuBuilder extends MenuBuilder { @Override public void onClick(View v) { Intent vint = new Intent(Intent.ACTION_VIEW); - vint.setDataAndType(FileProvider.getUriForFile(getApplication(), getMapActivity().getPackageName() + ".fileprovider", recording.getFile()), "image/*"); + vint.setDataAndType(AndroidUtils.getUriForFile(getApplication(),recording.getFile()) , "image/*"); vint.setFlags(0x10000000); vint.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); v.getContext().startActivity(vint); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 3b2226f877..c1e39a2228 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -25,7 +25,6 @@ import android.os.StatFs; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; -import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; import android.view.Display; import android.view.KeyEvent; @@ -828,7 +827,7 @@ 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 = FileProvider.getUriForFile(getMapActivity(), getMapActivity().getPackageName() + ".fileprovider", (getBaseFileName(lat, lon, app, IMG_EXTENSION))); + Uri fileUri = AndroidUtils.getUriForFile(getMapActivity(), getBaseFileName(lat, lon, app, IMG_EXTENSION)); 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,7 +841,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { // if (AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP) { // ext = THREEGP_EXTENSION; // } - Uri fileUri = FileProvider.getUriForFile(getMapActivity(), getMapActivity().getPackageName() + ".fileprovider", getBaseFileName(lat, lon, app, ext)); + Uri fileUri = AndroidUtils.getUriForFile(getMapActivity(), getBaseFileName(lat, lon, app, ext)); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high @@ -1504,7 +1503,7 @@ 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, FileProvider.getUriForFile(getMapActivity(), getMapActivity().getPackageName() + ".fileprovider",f)); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, AndroidUtils.getUriForFile(getMapActivity(),f)); takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { mapActivity.startActivityForResult(takePictureIntent, 205); @@ -1881,7 +1880,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public void playRecording(final Context ctx, final Recording r) { if (r.isVideo()) { Intent vint = new Intent(Intent.ACTION_VIEW); - vint.setDataAndType(FileProvider.getUriForFile(mapActivity,mapActivity.getPackageName() + ".fileprovider",r.file), "video/*"); + vint.setDataAndType(AndroidUtils.getUriForFile(mapActivity, r.file), "video/*"); vint.setFlags(0x10000000); try { ctx.startActivity(vint); @@ -1891,7 +1890,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { return; } else if (r.isPhoto()) { Intent vint = new Intent(Intent.ACTION_VIEW); - vint.setDataAndType(FileProvider.getUriForFile(mapActivity,mapActivity.getPackageName() + ".fileprovider",r.file), "image/*"); + vint.setDataAndType(AndroidUtils.getUriForFile(mapActivity, r.file), "image/*"); vint.setFlags(0x10000000); ctx.startActivity(vint); return; diff --git a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java index 6468daaa4f..3eec0ccfc5 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java @@ -10,7 +10,6 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; import android.view.LayoutInflater; @@ -27,6 +26,7 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast; +import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.data.PointDescription; import net.osmand.plus.GPXUtilities; @@ -463,7 +463,7 @@ public class NotesFragment extends OsmAndListFragment { for (Recording rec : selected) { File file = rec == SHARE_LOCATION_FILE ? generateGPXForRecordings(selected) : rec.getFile(); if (file != null) { - uris.add(FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider", file)); + uris.add(AndroidUtils.getUriForFile(getMyApplication(), file)); } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java index 1e4c759cd2..6b1add72db 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java @@ -7,7 +7,6 @@ import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; import android.support.design.widget.Snackbar; -import android.support.v4.content.FileProvider; import android.support.v4.view.ViewCompat; import android.view.LayoutInflater; import android.view.View; @@ -16,6 +15,7 @@ import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; +import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -61,7 +61,7 @@ public class DashErrorFragment extends DashBaseFragment { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$ File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH); - intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",file)); + intent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(),file)); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$ intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java index bfc5881a3a..65da97272a 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java @@ -7,7 +7,6 @@ import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.v4.content.FileProvider; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -15,6 +14,7 @@ import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; +import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -48,7 +48,7 @@ public class ErrorBottomSheetDialog extends BottomSheetDialogFragment { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$ File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH); - intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider", file)); + intent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), file)); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$ intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$ @@ -90,6 +90,7 @@ public class ErrorBottomSheetDialog extends BottomSheetDialogFragment { } public static boolean shouldShow(OsmandSettings settings, MapActivity activity) { - return true; + return activity.getMyApplication().getAppInitializer() + .checkPreviousRunsForExceptions(activity, settings != null); } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 6f82b84b4a..3c253b30d3 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -15,7 +15,6 @@ import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; -import android.support.v4.content.FileProvider; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; @@ -1411,7 +1410,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - final Uri fileUri = FileProvider.getUriForFile(getMyApplication(),getActivity().getPackageName() + ".fileprovider", gpxInfo.file); + final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), gpxInfo.file); final Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.setType("application/gpx+xml"); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 9b6afc3ee0..6ee6bed9fe 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -13,7 +13,6 @@ import android.support.annotation.Nullable; import android.support.design.widget.Snackbar; import android.support.v4.app.FragmentActivity; import android.support.v4.content.ContextCompat; -import android.support.v4.content.FileProvider; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; @@ -292,7 +291,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements private void shareItems() { GPXFile gpxFile = getGpx(); if (gpxFile != null) { - final Uri fileUri = FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider",new File(gpxFile.path)); + final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), new File(gpxFile.path)); final Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.setType("application/gpx+xml"); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 9eb5bb2dcd..47b4013e83 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -11,7 +11,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.content.FileProvider; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewCompat; @@ -152,7 +151,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - final Uri fileUri = FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider", new File(getGpx().path)); + final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), new File(getGpx().path)); final Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.setType("application/gpx+xml"); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 53f2bc0827..56415fd63e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -12,7 +12,6 @@ import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; import android.util.Xml; @@ -30,6 +29,7 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; +import net.osmand.AndroidUtils; import net.osmand.data.PointDescription; import net.osmand.osm.edit.Node; import net.osmand.plus.GPXUtilities; @@ -865,7 +865,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo final Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_osm_edits_subject)); - sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getMyApplication(), getMyApplication().getPackageName() + ".fileprovider", osmchange)); + sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), osmchange)); sendIntent.setType("text/plain"); sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(sendIntent); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index a267d6f562..cf8702f9ab 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -16,7 +16,6 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; -import android.support.v4.content.FileProvider; import android.support.v4.view.ViewPager; import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; @@ -2067,9 +2066,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "History.gpx:\n\n\n" + GPXUtilities.asString(gpxFile, app)); sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_history_subject)); - sendIntent.putExtra(Intent.EXTRA_STREAM, - FileProvider.getUriForFile(getActivity(), - getActivity().getPackageName() + ".fileprovider", dst)); + sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMapActivity(), dst)); sendIntent.setType("text/plain"); startActivity(sendIntent); } From 9ca3fed8107d0eb8077385071f4823ef4022dcde Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 21 May 2018 15:13:09 +0300 Subject: [PATCH 6/6] fix read_uri_permission --- .../osmand/plus/activities/ContributionVersionActivity.java | 1 - .../src/net/osmand/plus/activities/FavoritesTreeFragment.java | 1 + .../src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java | 4 +++- OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java | 1 + .../src/net/osmand/plus/search/QuickSearchDialogFragment.java | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java index 7941649a9c..19e48f9bf5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java @@ -111,7 +111,6 @@ public class ContributionVersionActivity extends OsmandListActivity { Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setDataAndType(AndroidUtils.getUriForFile(getMyApplication(), pathToDownload), "application/vnd.android.package-archive"); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivityForResult(intent, ACTIVITY_TO_INSTALL); updateInstalledApp(false, currentSelectedBuild.date); } diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index b6bc6a9bfd..8d78cec590 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -589,6 +589,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject)); sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), dst)); sendIntent.setType("text/plain"); + sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(sendIntent); } catch (IOException e) { Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_SHORT).show(); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index c1e39a2228..e79604e1f4 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -843,7 +843,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { // } Uri fileUri = AndroidUtils.getUriForFile(getMapActivity(), getBaseFileName(lat, lon, app, ext)); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name - + intent.addFlags(Intent.FLAG_GRANT_READ_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); @@ -1881,6 +1881,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { if (r.isVideo()) { Intent vint = new Intent(Intent.ACTION_VIEW); vint.setDataAndType(AndroidUtils.getUriForFile(mapActivity, r.file), "video/*"); + vint.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); vint.setFlags(0x10000000); try { ctx.startActivity(vint); @@ -1891,6 +1892,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } else if (r.isPhoto()) { Intent vint = new Intent(Intent.ACTION_VIEW); vint.setDataAndType(AndroidUtils.getUriForFile(mapActivity, r.file), "image/*"); + vint.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); vint.setFlags(0x10000000); ctx.startActivity(vint); return; diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 3c253b30d3..cf6b7283c4 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -1414,6 +1414,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { final Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.setType("application/gpx+xml"); + sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(sendIntent); return true; } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index cf8702f9ab..64f5fee00c 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -2068,6 +2068,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_history_subject)); sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMapActivity(), dst)); sendIntent.setType("text/plain"); + sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(sendIntent); } };