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.ap.jesus.migsv2.CamActivity.java

protected void saveScreenCaptureToExternalStorage(Bitmap screenCapture) {
    if (screenCapture != null) {
        // store screenCapture into external cache directory
        final File screenCaptureFile = new File(Environment.getExternalStorageDirectory().toString(),
                "screenCapture_" + System.currentTimeMillis() + ".jpg");

        // 1. Save bitmap to file & compress to jpeg. You may use PNG too
        try {//  w  w  w . j av  a2s .  c o m

            final FileOutputStream out = new FileOutputStream(screenCaptureFile);
            screenCapture.compress(Bitmap.CompressFormat.JPEG, 90, out);
            out.flush();
            out.close();

            // 2. create send intent
            final Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("image/jpg");
            share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(screenCaptureFile));

            // 3. launch intent-chooser
            final String chooserTitle = "Share Snaphot";
            CamActivity.this.startActivity(Intent.createChooser(share, chooserTitle));

        } catch (final Exception e) {
            // should not occur when all permissions are set
            CamActivity.this.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // show toast message in case something went wrong
                    Toast.makeText(CamActivity.this, "Unexpected error, " + e, Toast.LENGTH_LONG).show();
                }
            });
        }
    }
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * ??Intent??/*from  w  w  w  . ja v  a2s .  co m*/
 */
public static Intent createSendImageIntent(String filePath) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType(MediaUtils.getMimeType(filePath));
    intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath));
    return intent;
}

From source file:ca.rmen.android.poetassistant.PoemAudioExport.java

private PendingIntent getFileShareIntent() {
    // Bring up the chooser to share the file.
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    Uri uri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider",
            getAudioFile());// w  w w  .  j  a v a2  s.  c  o  m
    sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
    sendIntent.setType("audio/x-wav");
    return PendingIntent.getActivity(mContext, 0, sendIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.spectralinsights.locar.SampleCamActivity.java

protected void saveScreenCaptureToExternalStorage(Bitmap screenCapture) {
    if (screenCapture != null) {
        // store screenCapture into external cache directory
        final File screenCaptureFile = new File(Environment.getExternalStorageDirectory().toString(),
                "screenCapture_" + System.currentTimeMillis() + ".jpg");

        // 1. Save bitmap to file & compress to jpeg. You may use PNG too
        try {/*from  w ww .  j  a  v a2s  . c  om*/

            final FileOutputStream out = new FileOutputStream(screenCaptureFile);
            screenCapture.compress(Bitmap.CompressFormat.JPEG, 90, out);
            out.flush();
            out.close();

            // 2. create send intent
            final Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("image/jpg");
            share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(screenCaptureFile));

            // 3. launch intent-chooser
            final String chooserTitle = "Share Snaphot";
            SampleCamActivity.this.startActivity(Intent.createChooser(share, chooserTitle));

        } catch (final Exception e) {
            // should not occur when all permissions are set
            SampleCamActivity.this.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // show toast message in case something went wrong
                    Toast.makeText(SampleCamActivity.this, "Unexpected error, " + e, Toast.LENGTH_LONG).show();
                }
            });
        }
    }
}

From source file:de.j4velin.mapsmeasure.Dialogs.java

/**
 * @param c     the Context//from w w  w.j av a  2s. c  o  m
 * @param trace the current trace of points
 * @return the "save & share" dialog
 */
public static Dialog getSaveNShare(final Activity c, final Stack<LatLng> trace) {
    final Dialog d = new Dialog(c);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setContentView(R.layout.dialog_save);
    d.findViewById(R.id.save).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            final File destination;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO
                    && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                destination = API8Wrapper.getExternalFilesDir(c);
            } else {
                destination = c.getDir("traces", Context.MODE_PRIVATE);
            }

            d.dismiss();
            AlertDialog.Builder b = new AlertDialog.Builder(c);
            b.setTitle(R.string.save);
            final View layout = c.getLayoutInflater().inflate(R.layout.dialog_enter_filename, null);
            ((TextView) layout.findViewById(R.id.location))
                    .setText(c.getString(R.string.file_path, destination.getAbsolutePath() + "/"));
            b.setView(layout);
            b.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        String fname = ((EditText) layout.findViewById(R.id.filename)).getText().toString();
                        if (fname == null || fname.length() < 1) {
                            fname = "MapsMeasure_" + System.currentTimeMillis();
                        }
                        final File f = new File(destination, fname + ".csv");
                        Util.saveToFile(f, trace);
                        d.dismiss();
                        Toast.makeText(c, c.getString(R.string.file_saved, f.getAbsolutePath()),
                                Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                        Toast.makeText(c,
                                c.getString(R.string.error,
                                        e.getClass().getSimpleName() + "\n" + e.getMessage()),
                                Toast.LENGTH_LONG).show();
                    }
                }
            });
            b.create().show();
        }
    });
    d.findViewById(R.id.load).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {

            File[] files = c.getDir("traces", Context.MODE_PRIVATE).listFiles();

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO
                    && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                File ext = API8Wrapper.getExternalFilesDir(c);
                // even though we checked the external storage state, ext is still sometims null, accoring to Play Store crash reports
                if (ext != null) {
                    File[] filesExtern = ext.listFiles();
                    File[] allFiles = new File[files.length + filesExtern.length];
                    System.arraycopy(files, 0, allFiles, 0, files.length);
                    System.arraycopy(filesExtern, 0, allFiles, files.length, filesExtern.length);
                    files = allFiles;
                }
            }

            if (files.length == 0) {
                Toast.makeText(c,
                        c.getString(R.string.no_files_found,
                                c.getDir("traces", Context.MODE_PRIVATE).getAbsolutePath()),
                        Toast.LENGTH_SHORT).show();
            } else if (files.length == 1) {
                try {
                    Util.loadFromFile(Uri.fromFile(files[0]), (Map) c);
                    d.dismiss();
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(c,
                            c.getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                            Toast.LENGTH_LONG).show();
                }
            } else {
                d.dismiss();
                AlertDialog.Builder b = new AlertDialog.Builder(c);
                b.setTitle(R.string.select_file);
                final DeleteAdapter da = new DeleteAdapter(files, (Map) c);
                b.setAdapter(da, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            Util.loadFromFile(Uri.fromFile(da.getFile(which)), (Map) c);
                            dialog.dismiss();
                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(c,
                                    c.getString(R.string.error,
                                            e.getClass().getSimpleName() + "\n" + e.getMessage()),
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                });
                b.create().show();
            }
        }
    });
    d.findViewById(R.id.share).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            try {
                final File f = new File(c.getCacheDir(), "MapsMeasure.csv");
                Util.saveToFile(f, trace);
                Intent shareIntent = new Intent();
                shareIntent.setAction(Intent.ACTION_SEND);
                shareIntent.putExtra(Intent.EXTRA_STREAM,
                        FileProvider.getUriForFile(c, "de.j4velin.mapsmeasure.fileprovider", f));
                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                shareIntent.setType("text/comma-separated-values");
                d.dismiss();
                c.startActivity(Intent.createChooser(shareIntent, null));
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(c,
                        c.getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                        Toast.LENGTH_LONG).show();
            }
        }
    });
    return d;
}

From source file:com.zia.freshdocs.widget.CMISAdapter.java

/**
 * Send the content using a built-in Android activity which can handle the content type.
 * @param position//from   w ww  .jav a  2 s. co m
 */
public void shareContent(int position) {
    final NodeRef ref = getItem(position);
    downloadContent(ref, new Handler() {
        public void handleMessage(Message msg) {
            Context context = getContext();
            boolean done = msg.getData().getBoolean("done");

            if (done) {
                dismissProgressDlg();

                File file = (File) _dlThread.getResult();

                if (file != null) {
                    Resources res = context.getResources();
                    Uri uri = Uri.fromFile(file);
                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, ref.getName());
                    emailIntent.putExtra(Intent.EXTRA_TEXT, res.getString(R.string.email_text));
                    emailIntent.setType(ref.getContentType());

                    try {
                        context.startActivity(
                                Intent.createChooser(emailIntent, res.getString(R.string.email_title)));
                    } catch (ActivityNotFoundException e) {
                        String text = "No suitable applications registered to send " + ref.getContentType();
                        int duration = Toast.LENGTH_SHORT;
                        Toast toast = Toast.makeText(context, text, duration);
                        toast.show();
                    }
                }
            } else {
                int value = msg.getData().getInt("progress");
                if (value > 0) {
                    _progressDlg.setProgress(value);
                }
            }
        }
    });
}

From source file:gov.wa.wsdot.android.wsdot.ui.CameraImageFragment.java

private Intent createShareIntent() {
    File f = new File(getActivity().getFilesDir(), mCameraName);
    ContentValues values = new ContentValues(2);
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    values.put(MediaStore.Images.Media.DATA, f.getAbsolutePath());
    Uri uri = getActivity().getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    shareIntent.setType("image/jpeg");
    shareIntent.putExtra(Intent.EXTRA_TEXT, mTitle);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, mTitle);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

    return shareIntent;
}

From source file:net.evendanan.android.hagarfingerpainting.HagarFingerpaintingActivity.java

protected void onToolboxClicked(int id) {
    switch (id) {
    case R.id.toolbox_close:
        mToolbox.startAnimation(mOutAnimation);
        break;//from   ww w. ja  v  a2 s  . c om
    case R.id.toolbox_color:
        new ColorPickerDialog(this, mWhiteboard, 0).show();
        break;
    case R.id.toolbox_eraser:
        mEraseMode = !mEraseMode;
        mEraserToolBoxIcon.setBackgroundColor(mEraseMode ? Color.BLACK : Color.TRANSPARENT);
        mWhiteboard.setEraserMode(mEraseMode);
        break;
    case R.id.toolbox_save:
        takeScreenshot(true);
        break;
    case R.id.toolbox_share:
        File screenshotPath = takeScreenshot(false);
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("image/png");
        intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_title_template, getPainterName()));
        intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text_template, getPainterName()));
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(screenshotPath));
        try {
            startActivity(Intent.createChooser(intent, getString(R.string.toolbox_share_title)));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(this.getApplicationContext(), R.string.no_way_to_share, Toast.LENGTH_LONG).show();
        }
        break;
    case R.id.toolbox_new_paper:
        onNewPaperRequested();
        break;
    }
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

private void addFilesForTask(final Task t, final Intent intent) {
    final String action = intent.getAction();
    final String type = intent.getType();
    this.currentPosition = getTaskFragmentPosition();
    if (Intent.ACTION_SEND.equals(action) && (type != null)) {
        final Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        t.addFile(this, uri);
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && (type != null)) {
        final List<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        for (final Uri uri : imageUris) {
            t.addFile(this, uri);
        }/* www  . j  a  v  a2 s  .c o m*/
    }
}

From source file:net.gsantner.opoc.util.ShareUtil.java

/**
 * Share the given file as stream with given mime-type
 *
 * @param file     The file to share//w ww .  j a v a  2 s .  c o m
 * @param mimeType The files mime type
 */
public boolean shareStream(File file, String mimeType) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(EXTRA_FILEPATH, file.getAbsolutePath());
    intent.setType(mimeType);

    try {
        Uri fileUri = FileProvider.getUriForFile(_context, getFileProviderAuthority(), file);
        intent.putExtra(Intent.EXTRA_STREAM, fileUri);
        showChooser(intent, null);
        return true;
    } catch (Exception e) { // FileUriExposed(API24) / IllegalArgument
        return false;
    }
}