Fix sharing of multiple notes

This commit is contained in:
Alexander Sytnyk 2017-12-21 18:28:00 +02:00
parent d82e022750
commit 6c1bd8fe5e
2 changed files with 10 additions and 10 deletions

View file

@ -3,6 +3,9 @@
<cache-path <cache-path
name="share" name="share"
path="share" /> path="share"/>
<external-files-path
name="files"
path="/"/>
</paths> </paths>

View file

@ -10,6 +10,7 @@ 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;
@ -453,16 +454,17 @@ public class NotesFragment extends OsmAndListFragment {
} }
private void shareItems(Set<Recording> selected) { private void shareItems(Set<Recording> selected) {
ArrayList<Uri> files = new ArrayList<>(); ArrayList<Uri> uris = new ArrayList<>();
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) {
files.add(Uri.parse(file.getAbsolutePath())); uris.add(FileProvider.getUriForFile(getContext(), getActivity().getPackageName() + ".fileprovider", file));
} }
} }
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("*/*"); intent.setType("*/*");
intent.putExtra(Intent.EXTRA_STREAM, files); intent.putExtra(Intent.EXTRA_STREAM, uris);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (Build.VERSION.SDK_INT > 18) { if (Build.VERSION.SDK_INT > 18) {
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
@ -477,13 +479,8 @@ public class NotesFragment extends OsmAndListFragment {
return selected; return selected;
} }
@Nullable
private File generateGPXForRecordings(Set<Recording> selected) { private File generateGPXForRecordings(Set<Recording> selected) {
File externalCacheDir = getActivity().getExternalCacheDir(); File tmpFile = new File(getActivity().getCacheDir(), "share/noteLocations.gpx");
if (externalCacheDir == null) {
return null;
}
File tmpFile = new File(externalCacheDir, "share/noteLocations.gpx");
tmpFile.getParentFile().mkdirs(); tmpFile.getParentFile().mkdirs();
GPXFile file = new GPXFile(); GPXFile file = new GPXFile();
for (Recording r : getRecordingsForGpx(selected)) { for (Recording r : getRecordingsForGpx(selected)) {