change Uri.fromFile to FileProvider.getUriForFile

This commit is contained in:
Chumva 2018-05-21 14:06:19 +03:00
parent 730c394ac5
commit 625802e443
10 changed files with 32 additions and 20 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
});

View file

@ -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) {

View file

@ -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));
}
}

View file

@ -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();

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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);
}
}