src/main/java/de/dennisguse/opentracks/share/ShareUtils.java
public static Intent newShareFileIntent(Context context, Track.Id... trackIds) {
        if (trackIds.length == 0) {
            throw new RuntimeException("Need to share at least one track.");
        }

        ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);

        String trackDescription = "";
        if (trackIds.length == 1) {
            Track track = contentProviderUtils.getTrack(trackIds[0]);
            trackDescription = track == null ? "" : new DescriptionGenerator(context).generateTrackDescription(track, false);
        }

        String mime = "";
        ArrayList<Uri> uris = new ArrayList<>();
        for (Track.Id trackId : trackIds) {
            Track track = contentProviderUtils.getTrack(trackId);
            if (track == null) {
                Log.e(TAG, "TrackId " + trackId.getId() + " could not be resolved.");
                continue;
            }

            String trackName = FileUtils.sanitizeFileName(track.getName());
            Pair<Uri, String> uriAndMime = ShareContentProvider.createURI(trackId, trackName, PreferencesUtils.getExportTrackFileFormat());

            uris.add(uriAndMime.first);
            mime = uriAndMime.second;
        }

        return new Intent(Intent.ACTION_SEND_MULTIPLE)
                .setType(mime)
                .putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
                .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
                .putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.share_track_subject))
                .putExtra(Intent.EXTRA_TEXT, context.getString(R.string.share_track_share_file_body, trackDescription));
    }
/**
     * Creates an intent to share a track file with an app.
     *
     * @param context  the context
     * @param trackIds the track ids
     */
Creates an intent to share a track file with an app.
@param context  the context
@param trackIds the track ids
Creates an intent to share a track file with an app . @param context the context @param trackIds the track ids
public static Intent newShareFileIntent(Context context, Track.Id... trackIds) {
        if (trackIds.length == 0) {
            throw new RuntimeException("Need to share at least one track.");
        }
        ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
        String trackDescription = "";
        if (trackIds.length == 1) {
            Track track = contentProviderUtils.getTrack(trackIds[0]);
            trackDescription = track == null ? "" : new DescriptionGenerator(context).generateTrackDescription(track, false);
        }
        String mime = "";
        ArrayList<Uri> uris = new ArrayList<>();
        for (Track.Id trackId : trackIds) {
            Track track = contentProviderUtils.getTrack(trackId);
            if (track == null) {
                Log.e(TAG, "TrackId " + trackId.getId() + " could not be resolved.");
                continue;
            }
            String trackName = FileUtils.sanitizeFileName(track.getName());
            Pair<Uri, String> uriAndMime = ShareContentProvider.createURI(trackId, trackName, PreferencesUtils.getExportTrackFileFormat());
            uris.add(uriAndMime.first);
            mime = uriAndMime.second;
        }
        return new Intent(Intent.ACTION_SEND_MULTIPLE)
                .setType(mime)
                .putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
                .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
                .putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.share_track_subject))
                .putExtra(Intent.EXTRA_TEXT, context.getString(R.string.share_track_share_file_body, trackDescription));
    }
public static Intent newShareFileIntent ( Context context , Track . Id ... trackIds ) { if ( trackIds . length == 0 ) { throw new RuntimeException ( "Need to share at least one track." ) ; } ContentProviderUtils contentProviderUtils = new ContentProviderUtils ( context ) ; String trackDescription = "" ; if ( trackIds . length == 1 ) { Track track = contentProviderUtils . getTrack ( trackIds [ 0 ] ) ; trackDescription = track == null ? "" : new DescriptionGenerator ( context ) . generateTrackDescription ( track , false ) ; } String mime = "" ; ArrayList < Uri > uris = new ArrayList < > ( ) ; for ( Track . Id trackId : trackIds ) { Track track = contentProviderUtils . getTrack ( trackId ) ; if ( track == null ) { Log . e ( TAG , "TrackId " + trackId . getId ( ) + " could not be resolved." ) ; continue ; } String trackName = FileUtils . sanitizeFileName ( track . getName ( ) ) ; Pair < Uri , String > uriAndMime = ShareContentProvider . createURI ( trackId , trackName , PreferencesUtils . getExportTrackFileFormat ( ) ) ; uris . add ( uriAndMime . first ) ; mime = uriAndMime . second ; } return new Intent ( Intent . ACTION_SEND_MULTIPLE ) . setType ( mime ) . putParcelableArrayListExtra ( Intent . EXTRA_STREAM , uris ) . addFlags ( Intent . FLAG_GRANT_READ_URI_PERMISSION ) . putExtra ( Intent . EXTRA_SUBJECT , context . getString ( R . string . share_track_subject ) ) . putExtra ( Intent . EXTRA_TEXT , context . getString ( R . string . share_track_share_file_body , trackDescription ) ) ; }
Creates an intent to share a track file with an app.
Creates an intent to share a track file with an app .