Example usage for android.content Intent EXTRA_STREAM

List of usage examples for android.content Intent EXTRA_STREAM

Introduction

In this page you can find the example usage for android.content Intent EXTRA_STREAM.

Prototype

String EXTRA_STREAM

To view the source code for android.content Intent EXTRA_STREAM.

Click Source Link

Document

A content: URI holding a stream of data associated with the Intent, used with #ACTION_SEND to supply the data being sent.

Usage

From source file:com.flowzr.activity.BackupListActivity.java

private void startBackupToChooser(String backupFileName) {
    File file = Export.getBackupFile(this, backupFileName);
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    intent.setType("text/plain");
    startActivity(Intent.createChooser(intent, getString(R.string.backup_database_to_title)));
}

From source file:com.veniosg.dir.android.fragment.SimpleFileListFragment.java

private boolean handleMultipleSelectionAction(ActionMode mode, MenuItem item) {
    DialogFragment dialog;/*from   w w  w .  j  a v  a2 s .c o m*/
    Bundle args;
    ArrayList<FileHolder> fItems = getCheckedItems();

    switch (item.getItemId()) {
    case R.id.menu_send:
        mode.finish();
        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<Uri>();
        intent.setType("text/plain");

        for (FileHolder fh : fItems) {
            if (!fh.getFile().isDirectory())
                uris.add(FileUtils.getUri(fh));
        }

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

        try {
            startActivity(Intent.createChooser(intent, getString(R.string.send_chooser_title)));
            return true;
        } catch (ActivityNotFoundException e) {
            Toast.makeText(getActivity(), R.string.send_not_available, Toast.LENGTH_SHORT).show();
            return true;
        }
    case R.id.menu_delete:
        mode.finish();
        dialog = new MultiDeleteDialog();
        dialog.setTargetFragment(this, 0);
        args = new Bundle();
        args.putParcelableArrayList(IntentConstants.EXTRA_DIALOG_FILE_HOLDER,
                new ArrayList<Parcelable>(fItems));
        dialog.setArguments(args);
        dialog.show(getFragmentManager(), MultiDeleteDialog.class.getName());
        return true;
    case R.id.menu_move:
        mode.finish();
        ((FileManagerApplication) getActivity().getApplication()).getCopyHelper().cut(fItems);
        getActivity().supportInvalidateOptionsMenu();
        return true;
    case R.id.menu_copy:
        mode.finish();
        ((FileManagerApplication) getActivity().getApplication()).getCopyHelper().copy(fItems);
        getActivity().supportInvalidateOptionsMenu();
        return true;
    case R.id.menu_compress:
        mode.finish();
        dialog = new MultiCompressDialog();
        dialog.setTargetFragment(this, 0);
        args = new Bundle();
        args.putParcelableArrayList(IntentConstants.EXTRA_DIALOG_FILE_HOLDER,
                new ArrayList<Parcelable>(fItems));
        dialog.setArguments(args);
        dialog.show(getFragmentManager(), MultiCompressDialog.class.getName());
        return true;
    default:
        return false;
    }
}

From source file:com.zhongzilu.bit100.view.fragment.EditorFragment.java

private void shareMD() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mPresenter.getMDFile()));
    shareIntent.setType("*/*");

    //        startActivity(Intent.createChooser(share,"Share Image"));
    BottomSheet.Builder builder = new BottomSheet.Builder(getActivity());
    builder.setIntent(getActivity(), shareIntent);
    BottomSheet bottomSheet = builder.create();
    bottomSheet.show();//from   w w  w. ja  v  a 2  s .  co  m
}

From source file:com.squareup.leakcanary.internal.DisplayLeakActivity.java

private void startShareIntentChooser(Uri heapDumpUri) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("application/octet-stream");
    intent.putExtra(Intent.EXTRA_STREAM, heapDumpUri);
    startActivity(Intent.createChooser(intent, getString(R.string.leak_canary_share_with)));
}

From source file:com.albedinsky.android.support.intent.ShareIntent.java

/**
 *///w  w  w  .  j  av  a2s  .com
@NonNull
@Override
protected Intent onBuild() {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType(mDataType);
    if (!TextUtils.isEmpty(mTitle)) {
        intent.putExtra(Intent.EXTRA_TITLE, mTitle);
    }
    if (!TextUtils.isEmpty(mContent)) {
        intent.putExtra(Intent.EXTRA_TEXT, mContent);
    }
    if (mUri != null) {
        intent.putExtra(Intent.EXTRA_STREAM, mUri);
    } else if (mUris != null) {
        intent.setAction(Intent.ACTION_SEND_MULTIPLE);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<Parcelable>(mUris));
    }
    return intent;
}

From source file:me.xiaopan.sketchsample.fragment.DetailFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button_detail_share:
        File imageFile = getImageFile(uris.get(viewPager.getCurrentItem()), "");
        if (imageFile != null) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile));
            intent.setType("image/" + parseFileType(imageFile.getName()));
            List<ResolveInfo> infoList = getActivity().getPackageManager().queryIntentActivities(intent, 0);
            if (infoList != null && !infoList.isEmpty()) {
                startActivity(intent);/*from   w  w  w  .ja  va2 s .c o  m*/
            } else {
                Toast.makeText(getActivity(), "APP", Toast.LENGTH_LONG)
                        .show();
            }
        }
        break;
    case R.id.button_detail_applyWallpaper:
        File imageFile2 = getImageFile(uris.get(viewPager.getCurrentItem()), "?");
        if (imageFile2 != null) {
            new ApplyWallpaperAsyncTask(getActivity(), imageFile2) {
                @Override
                protected void onPostExecute(Boolean aBoolean) {
                    if (getActivity() != null) {
                        Toast.makeText(getActivity(), aBoolean ? "??" : "?",
                                Toast.LENGTH_LONG).show();
                    }
                }
            }.execute(0);
        }
        break;
    case R.id.button_detail_play:
        viewPagerPlayer.start();
        toggleToolbarVisibleState();
        break;
    case R.id.button_detail_save:
        String currentUri = uris.get(viewPager.getCurrentItem());
        if (currentUri == null || "".equals(currentUri.trim())) {
            Toast.makeText(getActivity(),
                    "??URL",
                    Toast.LENGTH_LONG).show();
        } else {
            UriScheme uriScheme = UriScheme.valueOfUri(currentUri);
            if (uriScheme == UriScheme.NET) {
                DiskCache.Entry imageFile3DiskCacheEntry = Sketch.with(getActivity()).getConfiguration()
                        .getDiskCache().get(currentUri);
                if (imageFile3DiskCacheEntry != null) {
                    new SaveImageAsyncTask(getActivity(), imageFile3DiskCacheEntry.getFile()).execute("");
                } else {
                    Toast.makeText(getActivity(), "???",
                            Toast.LENGTH_LONG).show();
                }
            } else if (uriScheme == UriScheme.ASSET) {
                new SaveAssetImageAsyncTask(getActivity(), UriScheme.ASSET.crop(currentUri)).execute("");
            } else if (uriScheme == UriScheme.CONTENT) {
                new SaveContentImageAsyncTask(getActivity(), Uri.parse(currentUri)).execute("");
            } else if (uriScheme == UriScheme.DRAWABLE) {
                new SaveResImageAsyncTask(getActivity(), Integer.valueOf(UriScheme.DRAWABLE.crop(currentUri)))
                        .execute("");
            } else if (uriScheme == UriScheme.FILE) {
                Toast.makeText(getActivity(), "??", Toast.LENGTH_LONG)
                        .show();
            } else {
                Toast.makeText(getActivity(), "URL " + currentUri,
                        Toast.LENGTH_LONG).show();
            }
        }
        break;
    }
}

From source file:com.duy.pascal.ui.file.FileExplorerAction.java

private void shareFile() {
    if (mCheckedList.isEmpty() || mShareActionProvider == null)
        return;//  w ww  .j  a v a2  s  .c om
    try {
        Intent shareIntent = new Intent();
        if (mCheckedList.size() == 1) {
            File file = new File(mCheckedList.get(0).getPath());
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.setType(MimeTypes.getInstance().getMimeType(file.getPath()));

            Uri fileUri;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                fileUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider",
                        file);
            } else {
                fileUri = Uri.fromFile(file);
            }
            shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);

            ArrayList<Uri> streams = new ArrayList<>();
            for (File file : mCheckedList) {
                File File = new File(file.getPath());
                Uri fileUri;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                    fileUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider",
                            File);
                } else {
                    fileUri = Uri.fromFile(File);
                }
                streams.add(fileUri);
            }

            shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, streams);
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        mShareActionProvider.setShareIntent(shareIntent);
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }
}

From source file:com.google.android.apps.location.gps.gnsslogger.FileLogger.java

/**
 * Send the current log via email or other options selected from a pop menu shown to the user. A
 * new log is started when calling this function.
 */// w w  w  . j  a  v  a2s.c om
public void send() {
    if (mFile == null) {
        return;
    }

    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setType("*/*");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "SensorLog");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "");
    // attach the file
    Uri fileURI = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".provider", mFile);
    emailIntent.putExtra(Intent.EXTRA_STREAM, fileURI);
    getUiComponent().startActivity(Intent.createChooser(emailIntent, "Send log.."));
    if (mFileWriter != null) {
        try {
            mFileWriter.flush();
            mFileWriter.close();
            mFileWriter = null;
        } catch (IOException e) {
            logException("Unable to close all file streams.", e);
            return;
        }
    }
}

From source file:im.vector.activity.VectorMediasViewerActivity.java

/**
 * Download the current video file/*from w w w  .j  ava  2s .  com*/
 */
private void onAction(final int position, final int action) {
    MXMediasCache mediasCache = Matrix.getInstance(this).getMediasCache();
    SlidableMediaInfo mediaInfo = mMediasList.get(position);

    File file = mediasCache.mediaCacheFile(mediaInfo.mMediaUrl, mediaInfo.mMimeType);

    // check if the media has already been downloaded
    if (null != file) {
        // download
        if (action == R.id.ic_action_download) {
            if (null != CommonActivityUtils.saveMediaIntoDownloads(this, file, mediaInfo.mFileName,
                    mediaInfo.mMimeType)) {
                Toast.makeText(this, getText(R.string.media_slider_saved), Toast.LENGTH_LONG).show();
            }
        } else {
            // shared
            Uri mediaUri = null;

            File renamedFile = file;

            if (!TextUtils.isEmpty(mediaInfo.mFileName))
                try {
                    InputStream fin = new FileInputStream(file);
                    String tmpUrl = mediasCache.saveMedia(fin, mediaInfo.mFileName, mediaInfo.mMimeType);

                    if (null != tmpUrl) {
                        renamedFile = mediasCache.mediaCacheFile(tmpUrl, mediaInfo.mMimeType);
                    }
                } catch (Exception e) {
                    Log.e(LOG_TAG, "## onAction() : mediasCache.mediaCacheFile.absolutePathToUri failed "
                            + e.getMessage());
                }

            if (null != renamedFile) {
                try {
                    mediaUri = VectorContentProvider.absolutePathToUri(this, renamedFile.getAbsolutePath());
                } catch (Exception e) {
                    Log.e(LOG_TAG,
                            "## onAction() : RiotContentProvider.absolutePathToUri failed " + e.getMessage());
                }
            }

            if (null != mediaUri) {
                try {
                    final Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.setType(mediaInfo.mMimeType);
                    sendIntent.putExtra(Intent.EXTRA_STREAM, mediaUri);
                    startActivity(sendIntent);
                } catch (Exception e) {
                    Log.e(LOG_TAG, "## onAction : cannot display the media " + mediaUri + " mimeType "
                            + mediaInfo.mMimeType);
                    CommonActivityUtils.displayToast(this, e.getLocalizedMessage());
                }
            }
        }
    } else {
        // else download it
        final String downloadId = mediasCache.downloadMedia(this, mSession.getHomeserverConfig(),
                mediaInfo.mMediaUrl, mediaInfo.mMimeType);

        if (null != downloadId) {
            mediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {
                @Override
                public void onDownloadError(String downloadId, JsonElement jsonElement) {
                    MatrixError error = JsonUtils.toMatrixError(jsonElement);

                    if ((null != error) && error.isSupportedErrorCode()) {
                        Toast.makeText(VectorMediasViewerActivity.this, error.getLocalizedMessage(),
                                Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onDownloadComplete(String aDownloadId) {
                    if (aDownloadId.equals(downloadId)) {
                        onAction(position, action);
                    }
                }
            });
        }
    }
}

From source file:im.neon.activity.VectorMediasViewerActivity.java

/**
 * Download the current video file/*from   ww  w  . j  a va  2  s . c  o  m*/
 */
private void onAction(final int position, final int action) {
    MXMediasCache mediasCache = Matrix.getInstance(this).getMediasCache();
    SlidableMediaInfo mediaInfo = mMediasList.get(position);

    File file = mediasCache.mediaCacheFile(mediaInfo.mMediaUrl, mediaInfo.mMimeType);

    // check if the media has already been downloaded
    if (null != file) {
        // download
        if (action == R.id.ic_action_download) {
            if (null != CommonActivityUtils.saveMediaIntoDownloads(this, file, mediaInfo.mFileName,
                    mediaInfo.mMimeType)) {
                Toast.makeText(this, getText(R.string.media_slider_saved), Toast.LENGTH_LONG).show();
            }
        } else {
            // shared
            Uri mediaUri = null;

            File renamedFile = file;

            if (!TextUtils.isEmpty(mediaInfo.mFileName))
                try {
                    InputStream fin = new FileInputStream(file);
                    String tmpUrl = mediasCache.saveMedia(fin, mediaInfo.mFileName, mediaInfo.mMimeType);

                    if (null != tmpUrl) {
                        renamedFile = mediasCache.mediaCacheFile(tmpUrl, mediaInfo.mMimeType);
                    }
                } catch (Exception e) {
                    Log.e(LOG_TAG, "## onAction() : mediasCache.mediaCacheFile.absolutePathToUri failed "
                            + e.getMessage());
                }

            if (null != renamedFile) {
                try {
                    mediaUri = VectorContentProvider.absolutePathToUri(this, renamedFile.getAbsolutePath());
                } catch (Exception e) {
                    Log.e(LOG_TAG,
                            "## onAction() : RiotContentProvider.absolutePathToUri failed " + e.getMessage());
                }
            }

            if (null != mediaUri) {
                try {
                    final Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.setType(mediaInfo.mMimeType);
                    sendIntent.putExtra(Intent.EXTRA_STREAM, mediaUri);
                    startActivity(sendIntent);
                } catch (Exception e) {
                    Log.e(LOG_TAG, "## onAction : cannot display the media " + mediaUri + " mimeType "
                            + mediaInfo.mMimeType);
                    CommonActivityUtils.displayToast(this, e.getLocalizedMessage());
                }
            }
        }
    } else {
        // else download it
        final String downloadId = mediasCache.downloadMedia(this, mSession.getHomeserverConfig(),
                mediaInfo.mMediaUrl, mediaInfo.mMimeType, mediaInfo.mEncryptedFileInfo);

        if (null != downloadId) {
            mediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {
                @Override
                public void onDownloadError(String downloadId, JsonElement jsonElement) {
                    MatrixError error = JsonUtils.toMatrixError(jsonElement);

                    if ((null != error) && error.isSupportedErrorCode()) {
                        Toast.makeText(VectorMediasViewerActivity.this, error.getLocalizedMessage(),
                                Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onDownloadComplete(String aDownloadId) {
                    if (aDownloadId.equals(downloadId)) {
                        onAction(position, action);
                    }
                }
            });
        }
    }
}