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:ca.rmen.android.networkmonitor.app.log.LogActionsActivity.java

/**
 * Run the given file export, then bring up the chooser intent to share the exported file.
 *///from  w  w  w .j  av a  2  s  .  c o m
private void shareFile(final FileExport fileExport) {
    Log.v(TAG, "shareFile " + fileExport);
    // Use a horizontal progress bar style if we can show progress of the export.
    String dialogMessage = getString(R.string.export_progress_preparing_export);
    int dialogStyle = fileExport != null ? ProgressDialog.STYLE_HORIZONTAL : ProgressDialog.STYLE_SPINNER;
    DialogFragmentFactory.showProgressDialog(this, dialogMessage, dialogStyle, PROGRESS_DIALOG_TAG);

    AsyncTask<Void, Void, File> asyncTask = new AsyncTask<Void, Void, File>() {

        @Override
        protected File doInBackground(Void... params) {
            File file = null;
            if (fileExport != null) {
                if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
                    return null;
                try {
                    // Export the file in the background.
                    file = fileExport.export();
                } catch (Throwable t) {
                    Log.e(TAG, "Error exporting file " + fileExport + ": " + t.getMessage(), t);
                }
                if (file == null)
                    return null;
            }

            String reportSummary = SummaryExport.getSummary(LogActionsActivity.this);
            // Bring up the chooser to share the file.
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_subject_send_log));

            String dateRange = SummaryExport.getDataCollectionDateRange(LogActionsActivity.this);

            String messageBody = getString(R.string.export_message_text, dateRange);
            if (file != null) {
                sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
                sendIntent.setType("message/rfc822");
                messageBody += getString(R.string.export_message_text_file_attached);
            } else {
                sendIntent.setType("text/plain");
            }
            messageBody += reportSummary;
            sendIntent.putExtra(Intent.EXTRA_TEXT, messageBody);

            startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.action_share)));
            return file;
        }

        @Override
        protected void onPostExecute(File result) {
            super.onPostExecute(result);
            DialogFragment fragment = (DialogFragment) getSupportFragmentManager()
                    .findFragmentByTag(PROGRESS_DIALOG_TAG);
            if (fragment != null)
                fragment.dismissAllowingStateLoss();
            // Show a toast if we failed to export a file.
            if (fileExport != null && result == null)
                Toast.makeText(LogActionsActivity.this, R.string.export_error_sdcard_unmounted,
                        Toast.LENGTH_LONG).show();
            finish();
        }

    };
    asyncTask.execute();
}

From source file:nl.mpcjanssen.simpletask.AddTask.java

private void noteToSelf(@NotNull Intent intent) {
    String task = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (intent.hasExtra(Intent.EXTRA_STREAM)) {
        Log.v(TAG, "Voice note added.");
    }/*  www  .jav  a 2 s  .  c om*/
    addBackgroundTask(task);
}

From source file:ch.luklanis.esscan.history.HistoryActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.history_menu_send_dta_save:
    case R.id.history_menu_send_dta_other:
    case R.id.history_menu_send_dta_email: {
        Message message = Message.obtain(mDataSentHandler, item.getItemId());
        createDTAFile(message);/* w  w w  .ja va2s.co m*/
    }
        break;
    case R.id.history_menu_send_csv: {
        CharSequence history = mHistoryManager.buildHistory();
        Uri historyFile = HistoryManager.saveHistory(history.toString());

        String[] recipients = new String[] { PreferenceManager.getDefaultSharedPreferences(this)
                .getString(PreferencesActivity.KEY_EMAIL_ADDRESS, "") };

        if (historyFile == null) {
            setOkAlert(R.string.msg_unmount_usb);
        } else {
            Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            intent.putExtra(Intent.EXTRA_EMAIL, recipients);
            String subject = getResources().getString(R.string.history_email_title);
            intent.putExtra(Intent.EXTRA_SUBJECT, subject);
            intent.putExtra(Intent.EXTRA_TEXT, subject);
            intent.putExtra(Intent.EXTRA_STREAM, historyFile);
            intent.setType("text/csv");
            startActivity(intent);
        }
    }
        break;
    case R.id.history_menu_clear: {
        new CancelOkDialog(R.string.msg_sure).setOkClickListener(new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                mHistoryManager.clearHistory();
                dialogInterface.dismiss();
                finish();
            }
        }).show(getFragmentManager(), "HistoryActivity.onOptionsItemSelected");
    }
        break;
    case android.R.id.home: {

        int error = PsDetailActivity.savePaymentSlip(this);

        if (error > 0) {
            setCancelOkAlert(this, error);
            return true;
        }

        NavUtils.navigateUpTo(this, new Intent(this, CaptureActivity.class));
        return true;
    }
    case R.id.history_menu_copy_code_row: {
        PsDetailFragment fragment = (PsDetailFragment) getFragmentManager()
                .findFragmentById(R.id.ps_detail_container);

        if (fragment != null) {
            String completeCode = fragment.getHistoryItem().getResult().getCompleteCode();

            addCodeRowToClipboard(completeCode);
        }
    }
        break;
    case R.id.history_menu_send_code_row: {
        PsDetailFragment fragment = (PsDetailFragment) getFragmentManager()
                .findFragmentById(R.id.ps_detail_container);

        if (fragment != null) {
            IEsrSender sender = getEsrSender();

            if (sender != null) {
                mSendingProgressDialog.show();

                fragment.send(PsDetailFragment.SEND_COMPONENT_CODE_ROW, sender,
                        this.historyFragment.getActivatedPosition());
            } else {
                Message message = Message.obtain(mDataSentHandler, R.id.es_send_failed);
                message.sendToTarget();
            }
        }
    }
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.horaapps.leafpic.PlayerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.action_share:
        Intent share = new Intent(Intent.ACTION_SEND);
        Media m = new Media(ContentHelper.getPath(getApplicationContext(), getIntent().getData()));
        share.setType(m.getMIME());//w w  w  .j  a v  a2s  .  c  o  m
        share.putExtra(Intent.EXTRA_STREAM, getIntent().getData());
        startActivity(Intent.createChooser(share, getString(R.string.send_to)));
        return true;

    case R.id.action_settings:
        startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
        return true;

    case R.id.rotate_layout:
        int rotation = (((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay()).getRotation();
        if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        else
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        showControls();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.hippo.nimingban.ui.GalleryActivity2.java

/**
 * @param uri the save image file url, null for fail
 * @param share true for share//from  www . ja  va 2 s  .  c  om
 */
public void onSaveTaskOver(Uri uri, boolean share) {
    if (mSaveTask != null) {
        mSaveTask = null;
    }

    if (share) {
        if (uri == null) {
            Toast.makeText(this, R.string.cant_save_image, Toast.LENGTH_SHORT).show();
        } else {
            String mimeType = getContentResolver().getType(uri);
            if (TextUtils.isEmpty(mimeType)) {
                mimeType = MimeTypeMap.getSingleton()
                        .getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(uri.toString()));
                if (TextUtils.isEmpty(mimeType)) {
                    mimeType = "image/*";
                }
            }
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setType(mimeType);
            startActivity(Intent.createChooser(intent, getString(R.string.share_image)));
        }
    } else {
        Toast.makeText(this, uri != null ? R.string.save_successfully : R.string.save_failed,
                Toast.LENGTH_SHORT).show();
    }
}

From source file:com.digitalarx.android.files.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, Uri.parse("file://" + file.getStoragePath()));
        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, file);
        chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);

    } else {//from  w  ww  .j  a v  a 2s .  c  o  m
        Log_OC.wtf(TAG, "Trying to send a NULL OCFile");
    }
}

From source file:foam.jellyfish.StarwispBuilder.java

public static void email(Context context, String emailTo, String emailCC, String subject, String emailText,
        List<String> filePaths) {
    //need to "send multiple" to get more than one attachment
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { emailTo });
    emailIntent.putExtra(android.content.Intent.EXTRA_CC, new String[] { emailCC });
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

    ArrayList<String> extra_text = new ArrayList<String>();
    extra_text.add(emailText);/*from   w ww  . j av a  2 s.  c  o m*/
    emailIntent.putStringArrayListExtra(Intent.EXTRA_TEXT, extra_text);
    //emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);

    //has to be an ArrayList
    ArrayList<Uri> uris = new ArrayList<Uri>();
    //convert from paths to Android friendly Parcelable Uri's
    for (String file : filePaths) {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

From source file:net.henryco.opalette.api.utils.Utils.java

public static void shareBitmapAction(Bitmap bitmap, String filename, Context activity, boolean saveAfter,
        Runnable... runnables) {//from www .  j  ava  2s .  c  o  m

    String file_name = filename;
    if (!file_name.endsWith(".png"))
        file_name += ".png";

    try {
        File cachePath = new File(activity.getCacheDir(), "images"); // see: res/xml/filepaths.xml

        if (cachePath.exists())
            deleteRecursive(cachePath);
        cachePath.mkdirs();

        FileOutputStream stream = new FileOutputStream(cachePath + "/" + file_name);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        stream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    File imagePath = new File(activity.getCacheDir(), "images");
    File newFile = new File(imagePath, file_name);
    Uri contentUri = FileProvider.getUriForFile(activity, "net.henryco.opalette.fileprovider", newFile);

    if (contentUri != null) {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file
        shareIntent.setType("image/png");
        shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
        activity.startActivity(Intent.createChooser(shareIntent, "Share"));
    }
    if (saveAfter)
        saveBitmapAction(bitmap, filename, activity, runnables);
}

From source file:com.jlcsoftware.callrecorder.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);/*  w w w .j  a  v  a  2 s.  co  m*/
        return true;
    }

    if (id == R.id.action_save) {
        if (null != selectedItems && selectedItems.length > 0) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    for (PhoneCallRecord record : selectedItems) {
                        record.getPhoneCall().setKept(true);
                        record.getPhoneCall().save(MainActivity.this);
                    }
                    LocalBroadcastManager.getInstance(MainActivity.this)
                            .sendBroadcast(new Intent(LocalBroadcastActions.NEW_RECORDING_BROADCAST)); // Causes refresh

                }
            };
            handler.post(runnable);
        }
        return true;
    }

    if (id == R.id.action_share) {
        if (null != selectedItems && selectedItems.length > 0) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    ArrayList<Uri> fileUris = new ArrayList<Uri>();
                    for (PhoneCallRecord record : selectedItems) {
                        fileUris.add(Uri.fromFile(new File(record.getPhoneCall().getPathToRecording())));
                    }
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris);
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_title));
                    shareIntent.putExtra(Intent.EXTRA_HTML_TEXT,
                            Html.fromHtml(getString(R.string.email_body_html)));
                    shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_body));
                    shareIntent.setType("audio/*");
                    startActivity(Intent.createChooser(shareIntent, getString(R.string.action_share)));
                }
            };
            handler.post(runnable);
        }
        return true;
    }

    if (id == R.id.action_delete) {
        if (null != selectedItems && selectedItems.length > 0) {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle(R.string.delete_recording_title);
            alert.setMessage(R.string.delete_recording_subject);
            alert.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {

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

                    Runnable runnable = new Runnable() {
                        @Override
                        public void run() {
                            Database callLog = Database.getInstance(MainActivity.this);
                            for (PhoneCallRecord record : selectedItems) {
                                int id = record.getPhoneCall().getId();
                                callLog.removeCall(id);
                            }

                            LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(
                                    new Intent(LocalBroadcastActions.RECORDING_DELETED_BROADCAST));
                        }
                    };
                    handler.post(runnable);

                    dialog.dismiss();

                }
            });
            alert.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {

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

                    dialog.dismiss();
                }
            });

            alert.show();
        }
        return true;
    }

    if (id == R.id.action_delete_all) {

        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(R.string.delete_recording_title);
        alert.setMessage(R.string.delete_all_recording_subject);
        alert.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {

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

                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        Database.getInstance(MainActivity.this).removeAllCalls(false);
                        LocalBroadcastManager.getInstance(getApplicationContext())
                                .sendBroadcast(new Intent(LocalBroadcastActions.RECORDING_DELETED_BROADCAST));
                    }
                };
                handler.post(runnable);

                dialog.dismiss();

            }
        });
        alert.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {

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

                dialog.dismiss();
            }
        });

        alert.show();

        return true;
    }

    if (R.id.action_whitelist == id) {
        if (permissionReadContacts) {
            Intent intent = new Intent(this, WhitelistActivity.class);
            startActivity(intent);
        } else {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle(R.string.permission_whitelist_title);
            alert.setMessage(R.string.permission_whitelist);
        }
        return true;
    }
    if (R.id.action_about == id) {
        AboutDialog.show(this);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:io.v.android.apps.reader.PdfViewerActivity.java

@Override
protected void onStart() {
    super.onStart();

    if (!mResolvingError) {
        mGoogleApiClient.connect();// w  ww . j  ava2  s. com
    }

    /**
     * Suppress the start process until the DB initialization is completed.
     * onStart() method will be called again after the user selects her blessings.
     */
    if (!getDB().isInitialized()) {
        return;
    }

    mDeviceSets = getDB().getDeviceSetList();
    mDeviceSets.setListener(new Listener() {
        @Override
        public void notifyItemChanged(int position) {
            if (mCurrentDS == null) {
                return;
            }

            DeviceSet changed = mDeviceSets.getItem(position);
            if (!changed.getId().equals(mCurrentDS.getId())) {
                return;
            }

            int oldPage = getPage();
            mCurrentDS = cloneDeviceSet(changed);
            int newPage = getPage();

            DeviceMeta dm = getDeviceMeta();

            if (oldPage != newPage) {
                mPdfView.setPage(dm.getPage());
                writeNavigationAction("Page Changed", newPage);
            }

            if (mMenuItemLinkPage != null) {
                mMenuItemLinkPage.setChecked(dm.getLinked());
            }
        }

        @Override
        public void notifyItemInserted(int position) {
            // Nothing to do
        }

        @Override
        public void notifyItemRemoved(int position) {
            // Nothing to do
        }
    });

    Intent intent = getIntent();

    if (intent.hasExtra(EXTRA_DEVICE_SET_ID)) {
        /**
         * Case #1.
         * The EXTRA_DEVICE_SET_ID value is set when this activity is started by touching one of
         * the existing device sets from the DeviceSetChooserActivity.
         */
        Log.i(TAG, "onStart: Case #1: started by selecting an existing device set.");

        // Get the device set from the DB and join it.
        DeviceSet ds = mDeviceSets.getItemById(intent.getStringExtra(EXTRA_DEVICE_SET_ID));

        // Use the post method to join the device set
        // only after the initial view layout is performed.
        mPdfView.post(() -> joinDeviceSet(ds));
    } else if (intent.getData() != null) {
        /**
         * Case #2.
         * The intent.getData() is set as a content Uri when this activity is started by using
         * the floating action button from the DeviceSetChooserActivity and selecting one of the
         * local PDF files from the browser.
         */
        Log.i(TAG, "onStart: Case #2: started by using the floating action button.");

        Uri uri = intent.getData();
        createAndJoinDeviceSet(uri);
    } else if (intent.hasExtra(Intent.EXTRA_STREAM)) {
        /**
         * Case #3.
         * The EXTRA_STREAM value is set when this activity is started by receiving an implicit
         * intent from another app by sharing a PDF file to the reader app.
         */
        Log.i(TAG, "onStart: Case #3: started by an implicit intent from another app.");

        Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        createAndJoinDeviceSet(uri);
    }
}