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.support.android.designlibdemo.activities.CampaignDetailActivity.java

public void setupShareIntent() {
    // Fetch Bitmap Uri locally
    ImageView ivImage = (ImageView) findViewById(R.id.ivCampaighnImage);
    // Get access to the URI for the bitmap
    Uri bmpUri = getLocalBitmapUri(ivImage);
    if (bmpUri != null) {
        // Construct a ShareIntent with link to image
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, campaign.getTitle());
        shareIntent.putExtra(Intent.EXTRA_TEXT, campaign.getCampaignUrl());
        shareIntent.setType("image/*");
        // Launch sharing dialog for image
        startActivity(Intent.createChooser(shareIntent, "send"));
    } else {//  w w w  .ja v  a2s .  c om
        Toast.makeText(this, "Some error occured during sharing", Toast.LENGTH_LONG).show();

    }

}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletActivity.java

public void handleExportTransactions() {

    // Create CSV file from transactions

    final File file = new File(Constants.Files.EXTERNAL_WALLET_BACKUP_DIR,
            Constants.Files.TX_EXPORT_NAME + "-" + getFileDate() + ".csv");

    try {//  w w  w  .j a  va2s.  c  o m

        final BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        writer.append("Date,Label,Amount (" + MonetaryFormat.CODE_PPC + "),Fee (" + MonetaryFormat.CODE_PPC
                + "),Address,Transaction Hash,Confirmations\n");

        if (txListAdapter == null || txListAdapter.transactions.isEmpty()) {
            longToast(R.string.export_transactions_mail_intent_failed);
            log.error("exporting transactions failed");
            return;
        }

        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm z");
        dateFormat.setTimeZone(TimeZone.getDefault());

        for (Transaction tx : txListAdapter.transactions) {

            TransactionsListAdapter.TransactionCacheEntry txCache = txListAdapter.getTxCache(tx);
            String memo = tx.getMemo() == null ? "" : StringEscapeUtils.escapeCsv(tx.getMemo());
            String fee = tx.getFee() == null ? "" : tx.getFee().toPlainString();
            String address = txCache.address == null ? getString(R.string.export_transactions_unknown)
                    : txCache.address.toString();

            writer.append(dateFormat.format(tx.getUpdateTime()) + ",");
            writer.append(memo + ",");
            writer.append(txCache.value.toPlainString() + ",");
            writer.append(fee + ",");
            writer.append(address + ",");
            writer.append(tx.getHash().toString() + ",");
            writer.append(tx.getConfidence().getDepthInBlocks() + "\n");

        }

        writer.flush();
        writer.close();

    } catch (IOException x) {
        longToast(R.string.export_transactions_mail_intent_failed);
        log.error("exporting transactions failed", x);
        return;
    }

    final DialogBuilder dialog = new DialogBuilder(this);
    dialog.setMessage(Html.fromHtml(getString(R.string.export_transactions_dialog_success, file)));

    dialog.setPositiveButton(WholeStringBuilder.bold(getString(R.string.export_keys_dialog_button_archive)),
            new OnClickListener() {

                @Override
                public void onClick(final DialogInterface dialog, final int which) {

                    final Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_transactions_mail_subject));
                    intent.putExtra(Intent.EXTRA_TEXT,
                            makeEmailText(getString(R.string.export_transactions_mail_text)));
                    intent.setType(Constants.MIMETYPE_TX_EXPORT);
                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

                    try {
                        startActivity(Intent.createChooser(intent,
                                getString(R.string.export_transactions_mail_intent_chooser)));
                        log.info("invoked chooser for exporting transactions");
                    } catch (final Exception x) {
                        longToast(R.string.export_transactions_mail_intent_failed);
                        log.error("exporting transactions failed", x);
                    }

                }

            });

    dialog.setNegativeButton(R.string.button_dismiss, null);
    dialog.show();

}

From source file:org.alfresco.mobile.android.application.manager.ActionManager.java

public static void actionSendDocuments(Fragment fr, List<File> files) {
    if (files.size() == 1) {
        actionSendDocument(fr, files.get(0));
        return;/*from w  w w . ja va  2  s .  c o  m*/
    }

    try {
        Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<Uri>();
        // convert from paths to Android friendly Parcelable Uri's
        for (File file : files) {
            Uri u = Uri.fromFile(file);
            uris.add(u);
        }
        i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        i.setType(MimeTypeManager.getMIMEType(fr.getActivity(), "text/plain"));
        fr.getActivity()
                .startActivity(Intent.createChooser(i, fr.getActivity().getText(R.string.share_content)));
    } catch (ActivityNotFoundException e) {
        MessengerManager.showToast(fr.getActivity(), R.string.error_unable_share_content);
    }
}

From source file:com.mbientlab.metawear.app.AccelerometerFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    checkboxes = new HashMap<>();
    checkboxes.put(CheckBoxName.TAP, (CheckBox) view.findViewById(R.id.checkBox1));
    checkboxes.put(CheckBoxName.SHAKE, (CheckBox) view.findViewById(R.id.checkBox2));
    checkboxes.put(CheckBoxName.ORIENTATION, (CheckBox) view.findViewById(R.id.checkBox3));
    checkboxes.put(CheckBoxName.FREE_FALL, (CheckBox) view.findViewById(R.id.checkBox4));
    checkboxes.put(CheckBoxName.SAMPLING, (CheckBox) view.findViewById(R.id.checkBox5));

    ((Button) view.findViewById(R.id.button3)).setOnClickListener(new OnClickListener() {
        @Override// ww  w.j a va  2s .  c  o  m
        public void onClick(View arg0) {
            if (mwMnger.controllerReady()) {
                accelController.stopComponents();
                accelController.disableAllDetection(true);
                for (CheckBox box : checkboxes.values()) {
                    box.setEnabled(true);
                }

            } else {
                Toast.makeText(getActivity(), R.string.error_connect_board, Toast.LENGTH_LONG).show();
            }
        }
    });
    ((Button) view.findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            if (mwMnger.controllerReady()) {
                if (checkboxes.get(CheckBoxName.TAP).isChecked()) {
                    accelController.enableTapDetection(TapType.values()[accelConfig.tapTypePos()],
                            Axis.values()[accelConfig.tapAxisPos()]);
                }
                if (checkboxes.get(CheckBoxName.SHAKE).isChecked()) {
                    accelController.enableShakeDetection(Axis.values()[accelConfig.shakeAxisPos()]);
                }
                if (checkboxes.get(CheckBoxName.ORIENTATION).isChecked()) {
                    accelController.enableOrientationDetection();
                }
                if (checkboxes.get(CheckBoxName.FREE_FALL).isChecked()) {
                    if (accelConfig.movementPos() == 0) {
                        accelController.enableFreeFallDetection();
                    } else {
                        accelController.enableMotionDetection(Axis.values());
                    }
                }
                if (checkboxes.get(CheckBoxName.SAMPLING).isChecked()) {
                    rmsValues = new Vector<>();
                    SamplingConfig config = accelController.enableXYZSampling();
                    config.withFullScaleRange(FullScaleRange.values()[accelConfig.fsrPos()])
                            .withOutputDataRate(OutputDataRate.values()[accelConfig.odrPos()]);
                    accelConfig.initialize(config.getBytes());
                    start = 0;
                }
                accelController.startComponents();

                for (CheckBox box : checkboxes.values()) {
                    box.setEnabled(false);
                }
            } else {
                Toast.makeText(getActivity(), R.string.error_connect_board, Toast.LENGTH_LONG).show();
            }
        }
    });
    ((Button) view.findViewById(R.id.button2)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final FragmentManager fm = getActivity().getSupportFragmentManager();
            final AccelerometerSettings dialog = new AccelerometerSettings();

            dialog.show(fm, "accelerometer_settings");
        }
    });
    ((Button) view.findViewById(R.id.textView10)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (accelConfig.polledBytes() == null) {
                Toast.makeText(getActivity(), R.string.error_no_accel_data, Toast.LENGTH_SHORT).show();
            } else {
                final FragmentManager fm = getActivity().getSupportFragmentManager();
                final DataPlotFragment dialog = new DataPlotFragment();

                dialog.show(fm, "resistance_graph_fragment");
            }
        }
    });
    ((Button) view.findViewById(R.id.textView11)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (accelConfig.polledBytes() == null) {
                Toast.makeText(getActivity(), R.string.error_no_accel_data, Toast.LENGTH_SHORT).show();
            } else {
                writeDataToFile();

                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_SUBJECT, "Logged Accelerometer Data");

                File file = getActivity().getFileStreamPath(dataFilename);
                Uri uri = FileProvider.getUriForFile(getActivity(), "com.mbientlab.metawear.app.fileprovider",
                        file);
                intent.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(Intent.createChooser(intent, "Send email..."));
            }
        }
    });
}

From source file:info.guardianproject.gpg.KeyListFragment.java

private void keyserverOperation(final int operation, final ActionMode mode) {
    new AsyncTask<Void, Void, Void>() {
        final Context context = getActivity().getApplicationContext();
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        final String host = prefs.getString(GpgPreferenceActivity.PREF_KEYSERVER,
                "ipv4.pool.sks-keyservers.net");
        final long[] selected = mListView.getCheckedItemIds();
        final Intent intent = new Intent(context, ImportFileActivity.class);

        @Override/* ww  w .j  a va 2 s.c  o  m*/
        protected Void doInBackground(Void... params) {
            HkpKeyServer keyserver = new HkpKeyServer(host);
            if (operation == DELETE_KEYS) {
                String args = "--batch --yes --delete-keys";
                for (int i = 0; i < selected.length; i++) {
                    args += " " + Long.toHexString(selected[i]);
                }
                GnuPG.gpg2(args);
            } else if (operation == KEYSERVER_SEND) {
                String args = "--keyserver " + host + " --send-keys ";
                for (int i = 0; i < selected.length; i++) {
                    args += " " + Long.toHexString(selected[i]);
                }
                // TODO this should use the Java keyserver stuff
                GnuPG.gpg2(args);
            } else if (operation == KEYSERVER_RECEIVE) {
                String keys = "";
                for (int i = 0; i < selected.length; i++) {
                    try {
                        keys += keyserver.get(selected[i]);
                        keys += "\n\n";
                    } catch (QueryException e) {
                        e.printStackTrace();
                    }
                }
                // An Intent can carry very much data, so write it
                // to a cached file
                try {
                    File privateFile = File.createTempFile("keyserver", ".pkr", mCurrentActivity.getCacheDir());
                    FileUtils.writeStringToFile(privateFile, keys);
                    intent.setType(getString(R.string.pgp_keys));
                    intent.setAction(Intent.ACTION_SEND);
                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(privateFile));
                } catch (IOException e) {
                    e.printStackTrace();
                    // try sending the key data inline in the Intent
                    intent.setType("text/plain");
                    intent.setAction(Intent.ACTION_SEND);
                    intent.putExtra(Intent.EXTRA_TEXT, keys);
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void v) {
            GpgApplication.triggerContactsSync();
            mCurrentActivity.setSupportProgressBarIndeterminateVisibility(false);
            mode.finish(); // Action picked, so close the CAB
            if (operation == KEYSERVER_RECEIVE)
                startActivity(intent);
        }
    }.execute();
}

From source file:com.z.stproperty.PropertyDetail.java

/**
 * User can share this property details with their friends through email as well
 * and can choose other options like whats-app, drop-box etc as well
 *///from www.j  av a2 s .c om
private void shareWithEmail() {
    try {
        String path = Images.Media.insertImage(getContentResolver(), SharedFunction.loadBitmap(shareImageLink),
                "title", null);
        Uri screenshotUri = Uri.parse(path);
        String shareContent = title + "\n\n" + prurl + "\n\n" + price + "\n\n";
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/png");
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
        intent.putExtra(Intent.EXTRA_SUBJECT, "Property to share with you");
        intent.putExtra(Intent.EXTRA_TEXT,
                "I think you might be interested in a property advertised on STProperty \n\n" + shareContent);
        intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
        SharedFunction.postAnalytics(PropertyDetail.this, "Lead", "Email Share", title);
        startActivity(Intent.createChooser(intent, ""));
    } catch (Exception e) {
        Log.e(this.getClass().getSimpleName(), e.getLocalizedMessage(), e);
    }
}

From source file:mp.paschalis.EditBookActivity.java

/**
 * Creates a sharing {@link Intent}./*  w  w w .ja v  a2  s.  com*/
 *
 * @return The sharing intent.
 */
private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");

    String root = Environment.getExternalStorageDirectory() + ".SmartLib/Images";
    new File(root).mkdirs();

    File file = new File(root, app.selectedBook.isbn);

    try {
        FileOutputStream os = new FileOutputStream(file);
        bitmapBookCover.compress(CompressFormat.PNG, 80, os);
        os.flush();
        os.close();

        Uri uri = Uri.fromFile(file);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

    } catch (Exception e) {
        Log.e(TAG, e.getStackTrace().toString());
    }

    String bookInfo = "\n\n\n\nMy " + getString(R.string.bookInfo) + ":\n" + getString(R.string.title)
            + ": \t\t\t\t" + app.selectedBook.title + "\n" + getString(R.string.author) + ": \t\t\t"
            + app.selectedBook.authors + "\n" + getString(R.string.isbn) + ": \t\t\t\t" + app.selectedBook.isbn
            + "\n" + getString(R.string.published_) + " \t" + app.selectedBook.publishedYear + "\n"
            + getString(R.string.pages_) + " \t\t\t" + app.selectedBook.pageCount + "\n"
            + getString(R.string.isbn) + ": \t\t\t\t" + app.selectedBook.isbn + "\n"
            + getString(R.string.status) + ": \t\t\t"
            + App.getBookStatusString(app.selectedBook.status, EditBookActivity.this) + "\n\n"
            + "http://books.google.com/books?vid=isbn" + app.selectedBook.isbn;

    shareIntent.putExtra(Intent.EXTRA_TEXT, bookInfo);

    return shareIntent;
}

From source file:com.owncloud.android.ui.helpers.FileOperationsHelper.java

public void sendDownloadedFile(OCFile file) {
    if (file != null) {
        Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
        // set MimeType
        sendIntent.setType(file.getMimetype());
        sendIntent.putExtra(Intent.EXTRA_STREAM, file.getExposedFileUri(mFileActivity));
        sendIntent.putExtra(Intent.ACTION_SEND, true); // Send Action

        // Show dialog, without the own app
        String[] packagesToExclude = new String[] { mFileActivity.getPackageName() };
        DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent, packagesToExclude);
        chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);

    } else {//from  w  ww  .  jav  a  2 s .  c  om
        Log_OC.e(TAG, "Trying to send a NULL OCFile");
    }
}

From source file:nl.sogeti.android.gpstracker.actions.ShareTrack.java

private void sendFile(Uri fileUri, String body, String contentType) {
    Intent sendActionIntent = new Intent(Intent.ACTION_SEND);
    sendActionIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject));
    sendActionIntent.putExtra(Intent.EXTRA_TEXT, body);
    sendActionIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
    sendActionIntent.setType(contentType);
    startActivity(Intent.createChooser(sendActionIntent, getString(R.string.sender_chooser)));
}

From source file:com.orpheusdroid.screenrecorder.adapter.VideoRecyclerAdapter.java

/**
 * Share the videos selected//from   w  ww  . j  a v a  2s.  c o m
 *
 * @param positions Integer ArrayList containing the positions of the videos to be shared
 *
 * @see #shareVideo(int postion)
 */
private void shareVideos(ArrayList<Integer> positions) {
    ArrayList<Uri> videoList = new ArrayList<>();
    for (int position : positions) {
        videoList.add(FileProvider.getUriForFile(context, context.getPackageName() + ".provider",
                videos.get(position).getFile()));
    }
    Intent Shareintent = new Intent().setAction(Intent.ACTION_SEND_MULTIPLE).setType("video/*")
            .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            .putParcelableArrayListExtra(Intent.EXTRA_STREAM, videoList);
    context.startActivity(
            Intent.createChooser(Shareintent, context.getString(R.string.share_intent_notification_title)));
}