Use file provider to share notes

This commit is contained in:
Victor Shcherb 2015-08-31 09:08:57 +02:00
parent 47b4d3151a
commit 6da63d4685
3 changed files with 31 additions and 3 deletions

View file

@ -59,6 +59,16 @@
<activity android:name="net.osmand.plus.activities.HelpActivity" /> <activity android:name="net.osmand.plus.activities.HelpActivity" />
<activity android:name="net.osmand.plus.activities.ExitActivity" /> <activity android:name="net.osmand.plus.activities.ExitActivity" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="net.osmand.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths" />
</provider>
<activity android:name="net.osmand.plus.activities.MapActivity" android:label="@string/app_name" <activity android:name="net.osmand.plus.activities.MapActivity" android:label="@string/app_name"
android:screenOrientation="unspecified" android:launchMode="singleTop"> android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter> <intent-filter>

8
OsmAnd/res/xml/paths.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path
name="share"
path="share" />
</paths>

View file

@ -22,6 +22,7 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.util.Algorithms;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -31,6 +32,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
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.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
@ -222,10 +224,17 @@ public class NotesFragment extends OsmAndListFragment {
if(path == shareLocationFile) { if(path == shareLocationFile) {
File fl = generateGPXForRecordings(selected); File fl = generateGPXForRecordings(selected);
if(fl != null) { if(fl != null) {
files.add(Uri.fromFile(fl)); files.add(FileProvider.getUriForFile(getActivity(), "net.osmand.fileprovider", fl));
} }
} else { } else {
files.add(Uri.fromFile(path.getFile())); File src = path.getFile();
File dst = new File(getActivity().getCacheDir(), "share/"+src.getName());
try {
Algorithms.fileCopy(src, dst);
files.add(FileProvider.getUriForFile(getActivity(), "net.osmand.fileprovider", dst));
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
@ -234,7 +243,8 @@ public class NotesFragment extends OsmAndListFragment {
} }
private File generateGPXForRecordings(ArrayList<Recording> selected) { private File generateGPXForRecordings(ArrayList<Recording> selected) {
File tmpFile = getMyApplication().getAppPath("cache/noteLocations.gpx"); // File tmpFile = getMyApplication().getAppPath("cache/noteLocations.gpx");
File tmpFile = new File(getActivity().getCacheDir(), "share/noteLocations.gpx");
tmpFile.getParentFile().mkdirs(); tmpFile.getParentFile().mkdirs();
GPXFile file = new GPXFile(); GPXFile file = new GPXFile();
for(Recording r : selected) { for(Recording r : selected) {