Merge pull request #5451 from osmandapp/ChumvaFixes

Fix FileUriExposedException
This commit is contained in:
Alexey 2018-05-21 16:26:56 +03:00 committed by GitHub
commit 10d3a61782
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 52 additions and 37 deletions

View file

@ -12,6 +12,7 @@ import android.graphics.Paint;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable; import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.support.annotation.AttrRes; import android.support.annotation.AttrRes;
@ -20,6 +21,7 @@ import android.support.annotation.ColorRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.TextPaint; import android.text.TextPaint;
@ -109,6 +111,10 @@ public class AndroidUtils {
return src; 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) { public static Spannable replaceCharsWithIcon(String text, Drawable icon, String[] chars) {
Spannable spannable = new SpannableString(text); Spannable spannable = new SpannableString(text);
for (String entry : chars) { for (String entry : chars) {

View file

@ -3,7 +3,6 @@ package net.osmand.plus.activities;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -111,8 +110,8 @@ public class ContributionVersionActivity extends OsmandListActivity {
if(currentSelectedBuild != null){ if(currentSelectedBuild != null){
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(Uri.fromFile(pathToDownload), "application/vnd.android.package-archive"); intent.setDataAndType(AndroidUtils.getUriForFile(getMyApplication(), pathToDownload), "application/vnd.android.package-archive");
startActivityForResult(intent, ACTIVITY_TO_INSTALL); startActivityForResult(intent, ACTIVITY_TO_INSTALL);
updateInstalledApp(false, currentSelectedBuild.date); updateInstalledApp(false, currentSelectedBuild.date);
} }
} }

View file

@ -12,7 +12,6 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
@ -32,6 +31,7 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
@ -587,10 +587,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
} }
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtmlPrint(groups).toString())); 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_SUBJECT, getString(R.string.share_fav_subject));
sendIntent.putExtra(Intent.EXTRA_STREAM, sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), dst));
FileProvider.getUriForFile(getActivity(),
getActivity().getPackageName() + ".fileprovider", dst));
sendIntent.setType("text/plain"); sendIntent.setType("text/plain");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(sendIntent); startActivity(sendIntent);
} catch (IOException e) { } catch (IOException e) {
Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_SHORT).show();

View file

@ -13,7 +13,6 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.content.FileProvider;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Html; import android.text.Html;
import android.text.TextUtils; 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.ChartTouchListener;
import com.github.mikephil.charting.listener.OnChartGestureListener; import com.github.mikephil.charting.listener.OnChartGestureListener;
import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
@ -440,7 +440,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final GPXFile gpx = helper.generateGPXFileWithRoute(); final GPXFile gpx = helper.generateGPXFileWithRoute();
final Uri fileUri = Uri.fromFile(new File(gpx.path)); final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), new File(gpx.path));
File dir = new File(getActivity().getCacheDir(), "share"); File dir = new File(getActivity().getCacheDir(), "share");
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdir(); dir.mkdir();
@ -457,10 +457,9 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_route_subject)); sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_route_subject));
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
sendIntent.putExtra( sendIntent.putExtra(
Intent.EXTRA_STREAM, Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), dst));
FileProvider.getUriForFile(getActivity(),
getActivity().getPackageName() + ".fileprovider", dst));
sendIntent.setType("text/plain"); sendIntent.setType("text/plain");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(sendIntent); startActivity(sendIntent);
} catch (IOException e) { } catch (IOException e) {
// Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), // Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(),
@ -560,7 +559,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
void print() { void print() {
File file = generateRouteInfoHtml(adapter, helper.getGeneralRouteInformation()); File file = generateRouteInfoHtml(adapter, helper.getGeneralRouteInformation());
if (file.exists()) { if (file.exists()) {
Uri uri = Uri.fromFile(file); Uri uri = AndroidUtils.getUriForFile(getMyApplication(), file);
Intent browserIntent; Intent browserIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // use Android Print Framework if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // use Android Print Framework
browserIntent = new Intent(getActivity(), PrintDialogActivity.class) browserIntent = new Intent(getActivity(), PrintDialogActivity.class)
@ -569,6 +568,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
browserIntent = new Intent(Intent.ACTION_VIEW).setDataAndType( browserIntent = new Intent(Intent.ACTION_VIEW).setDataAndType(
uri, "text/html"); uri, "text/html");
} }
browserIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(browserIntent); startActivity(browserIntent);
} }
} }

View file

@ -4,13 +4,13 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.net.Uri;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import net.osmand.AndroidUtils;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
@ -64,8 +64,9 @@ public class AudioVideoNoteMenuBuilder extends MenuBuilder {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Intent vint = new Intent(Intent.ACTION_VIEW); Intent vint = new Intent(Intent.ACTION_VIEW);
vint.setDataAndType(Uri.fromFile(recording.getFile()), "image/*"); vint.setDataAndType(AndroidUtils.getUriForFile(getApplication(),recording.getFile()) , "image/*");
vint.setFlags(0x10000000); vint.setFlags(0x10000000);
vint.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
v.getContext().startActivity(vint); v.getContext().startActivity(vint);
} }
}); });

View file

@ -827,8 +827,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public void captureImage(double lat, double lon, final MapActivity mapActivity) { public void captureImage(double lat, double lon, final MapActivity mapActivity) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri fileUri = Uri.fromFile(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.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// start the image capture Intent // start the image capture Intent
mapActivity.startActivityForResult(intent, 105); mapActivity.startActivityForResult(intent, 105);
} }
@ -840,9 +841,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
// if (AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP) { // if (AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP) {
// ext = THREEGP_EXTENSION; // ext = THREEGP_EXTENSION;
// } // }
Uri fileUri = Uri.fromFile(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_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 intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high
// start the video capture Intent // start the video capture Intent
mapActivity.startActivityForResult(intent, 205); mapActivity.startActivityForResult(intent, 205);
@ -1502,7 +1503,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
final File f = getBaseFileName(lat, lon, app, IMG_EXTENSION); final File f = getBaseFileName(lat, lon, app, IMG_EXTENSION);
lastTakingPhoto = f; lastTakingPhoto = f;
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, AndroidUtils.getUriForFile(getMapActivity(),f));
takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try { try {
mapActivity.startActivityForResult(takePictureIntent, 205); mapActivity.startActivityForResult(takePictureIntent, 205);
} catch (Exception e) { } catch (Exception e) {
@ -1878,7 +1880,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public void playRecording(final Context ctx, final Recording r) { public void playRecording(final Context ctx, final Recording r) {
if (r.isVideo()) { if (r.isVideo()) {
Intent vint = new Intent(Intent.ACTION_VIEW); Intent vint = new Intent(Intent.ACTION_VIEW);
vint.setDataAndType(Uri.fromFile(r.file), "video/*"); vint.setDataAndType(AndroidUtils.getUriForFile(mapActivity, r.file), "video/*");
vint.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
vint.setFlags(0x10000000); vint.setFlags(0x10000000);
try { try {
ctx.startActivity(vint); ctx.startActivity(vint);
@ -1888,7 +1891,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return; return;
} else if (r.isPhoto()) { } else if (r.isPhoto()) {
Intent vint = new Intent(Intent.ACTION_VIEW); Intent vint = new Intent(Intent.ACTION_VIEW);
vint.setDataAndType(Uri.fromFile(r.file), "image/*"); vint.setDataAndType(AndroidUtils.getUriForFile(mapActivity, r.file), "image/*");
vint.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
vint.setFlags(0x10000000); vint.setFlags(0x10000000);
ctx.startActivity(vint); ctx.startActivity(vint);
return; return;

View file

@ -10,7 +10,6 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -27,6 +26,7 @@ import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
@ -463,7 +463,7 @@ public class NotesFragment extends OsmAndListFragment {
for (Recording rec : selected) { for (Recording rec : selected) {
File file = rec == SHARE_LOCATION_FILE ? generateGPXForRecordings(selected) : rec.getFile(); File file = rec == SHARE_LOCATION_FILE ? generateGPXForRecordings(selected) : rec.getFile();
if (file != null) { if (file != null) {
uris.add(FileProvider.getUriForFile(getContext(), getActivity().getPackageName() + ".fileprovider", file)); uris.add(AndroidUtils.getUriForFile(getMyApplication(), file));
} }
} }

View file

@ -4,7 +4,6 @@ import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
@ -16,6 +15,7 @@ import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -61,7 +61,8 @@ public class DashErrorFragment extends DashBaseFragment {
Intent intent = new Intent(Intent.ACTION_SEND); Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$ intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$
File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH); File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(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.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$ intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();

View file

@ -7,7 +7,6 @@ import android.graphics.Typeface;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -15,6 +14,7 @@ import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -48,7 +48,8 @@ public class ErrorBottomSheetDialog extends BottomSheetDialogFragment {
Intent intent = new Intent(Intent.ACTION_SEND); Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$ intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$
File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH); 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, AndroidUtils.getUriForFile(getMyApplication(), file));
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$ intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$ intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();

View file

@ -595,7 +595,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
asyncLoader.cancel(true); if (asyncLoader != null && asyncLoader.getStatus() == AsyncTask.Status.RUNNING) {
asyncLoader.cancel(true);
}
} }

View file

@ -1410,10 +1410,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
final Uri fileUri = Uri.fromFile(gpxInfo.file); final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), gpxInfo.file);
final Intent sendIntent = new Intent(Intent.ACTION_SEND); final Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
sendIntent.setType("application/gpx+xml"); sendIntent.setType("application/gpx+xml");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(sendIntent); startActivity(sendIntent);
return true; return true;
} }

View file

@ -291,10 +291,11 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
private void shareItems() { private void shareItems() {
GPXFile gpxFile = getGpx(); GPXFile gpxFile = getGpx();
if (gpxFile != null) { if (gpxFile != null) {
final Uri fileUri = Uri.fromFile(new File(gpxFile.path)); final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), new File(gpxFile.path));
final Intent sendIntent = new Intent(Intent.ACTION_SEND); final Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
sendIntent.setType("application/gpx+xml"); sendIntent.setType("application/gpx+xml");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(sendIntent); startActivity(sendIntent);
} }
} }

View file

@ -151,10 +151,11 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
final Uri fileUri = Uri.fromFile(new File(getGpx().path)); final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), new File(getGpx().path));
final Intent sendIntent = new Intent(Intent.ACTION_SEND); final Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
sendIntent.setType("application/gpx+xml"); sendIntent.setType("application/gpx+xml");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(sendIntent); startActivity(sendIntent);
return true; return true;
} }

View file

@ -4,7 +4,6 @@ import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -30,6 +29,7 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
@ -865,8 +865,9 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
final Intent sendIntent = new Intent(); final Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_osm_edits_subject)); 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, AndroidUtils.getUriForFile(getMyApplication(), osmchange));
sendIntent.setType("text/plain"); sendIntent.setType("text/plain");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(sendIntent); startActivity(sendIntent);
} }
} }

View file

@ -16,7 +16,6 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -2067,10 +2066,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "History.gpx:\n\n\n" + GPXUtilities.asString(gpxFile, app)); 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_SUBJECT, getString(R.string.share_history_subject));
sendIntent.putExtra(Intent.EXTRA_STREAM, sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMapActivity(), dst));
FileProvider.getUriForFile(getActivity(),
getActivity().getPackageName() + ".fileprovider", dst));
sendIntent.setType("text/plain"); sendIntent.setType("text/plain");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(sendIntent); startActivity(sendIntent);
} }
}; };