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:org.alfresco.mobile.android.application.fragments.fileexplorer.FileActions.java

private void send(Fragment fragment, List<File> selectedFiles) {
    Intent pickResult = new Intent();
    if (selectedFiles.size() == 0) {
        pickResult.setData(Uri.fromFile(selectedFiles.get(0)));
    } else if (selectedFiles.size() > 0) {
        ArrayList<Uri> uris = new ArrayList<Uri>();
        for (File file : selectedFiles) {
            Uri u = Uri.fromFile(file);//from w w  w.  j  av  a  2 s  . co  m
            uris.add(u);
        }
        pickResult.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    }
    fragment.getActivity().setResult(FragmentActivity.RESULT_OK, pickResult);
    fragment.getActivity().finish();

}

From source file:com.sspai.dkjt.service.GenerateFrameService.java

@Override
public void doneImage(final Uri imageUri) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override/*ww  w  .  java  2  s .  c  o m*/
        public void run() {
            bus.post(new Events.SingleImageProcessed(device, imageUri));
        }
    });

    // Create the intent to let the user share the image
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("image/png");
    sharingIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    Intent chooserIntent = Intent.createChooser(sharingIntent, null);
    chooserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationBuilder.addAction(R.drawable.ic_action_share, getResources().getString(R.string.share),
            PendingIntent.getActivity(this, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT));

    // Create the intent to let the user rate the app
    Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(ConfigString.MARKET_URL));
    notificationBuilder.addAction(R.drawable.ic_action_rate, getResources().getString(R.string.rate),
            PendingIntent.getActivity(this, 0, rateIntent, PendingIntent.FLAG_CANCEL_CURRENT));

    // Create the intent to show the screenshot in gallery
    Intent launchIntent = new Intent(Intent.ACTION_VIEW);
    launchIntent.setDataAndType(imageUri, "image/png");
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    notificationBuilder.setContentTitle(resources.getString(R.string.screenshot_saved_title))
            .setContentText(resources.getString(R.string.single_screenshot_saved, device.name()))
            .setContentIntent(PendingIntent.getActivity(this, 0, launchIntent, 0))
            .setWhen(System.currentTimeMillis()).setProgress(0, 0, false).setAutoCancel(true);

    notificationManager.notify(DFG_NOTIFICATION_ID, notificationBuilder.build());
}

From source file:com.qiscus.sdk.ui.QiscusPhotoViewerActivity.java

private void shareImage(File imageFile) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/jpg");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile));
    startActivity(Intent.createChooser(intent, "Share"));
}

From source file:com.wit.android.support.content.intent.ShareIntent.java

/**
 *///from   w w  w .j  a  va 2 s  . com
@Nullable
@Override
public Intent buildIntent() {
    if (TextUtils.isEmpty(mDataType)) {
        Log.e(TAG, "Can not to create SHARE intent. Missing MIME type.");
        return null;
    }
    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, mUris);
    }
    return intent;
}

From source file:jamesmorrisstudios.com.randremind.activities.MainActivity.java

private void processIntents() {
    Intent intent = getIntent();//  www  . jav a2  s  .c  om
    if (intent == null) {
        return;
    }
    String action = intent.getAction();
    String type = intent.getType();
    //If we are opening from a reminder notification click go straight to that reminder page
    if (intent.hasExtra("REMINDER") && intent.hasExtra("NAME")) {
        if (loadReminderListSync(intent)) {
            Log.v("Main Activity", "Intent received to go to reminder");
            ReminderList.getInstance().setCurrentReminder(intent.getStringExtra("NAME"));
            clearForOpen(intent);
            loadSummaryFragment();
        }
    } else if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_VIEW.equals(action)) && type != null) {
        Log.v("MainActivity", "Shared text " + type);
        Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (uri == null) {
            uri = intent.getData();
        }
        if (uri != null) {
            clearForOpen(intent);
            loadBackupRestoreFragment(uri);
        }
    }
}

From source file:ca.rmen.android.networkmonitor.app.dbops.ui.Share.java

/**
 * Run the given file export, then bring up the chooser intent to share the exported file.
 * The progress will be displayed in a progress dialog on the given activity.
 *///from   ww  w  .ja  v a 2  s . c om
private static void shareFile(final FragmentActivity activity, final FileExport fileExport) {
    Log.v(TAG, "shareFile " + fileExport);

    Bundle bundle = new Bundle(1);
    bundle.putString(DBOpAsyncTask.EXTRA_DIALOG_MESSAGE,
            activity.getString(R.string.export_progress_preparing_export));
    new DBOpAsyncTask<File>(activity, fileExport, bundle) {

        @Override
        protected File doInBackground(Void... params) {
            Log.v(TAG, "doInBackground");
            File file = null;
            if (fileExport != null) {
                if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
                    return null;
                file = super.doInBackground(params);
                if (file == null)
                    return null;
            }

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

            String dateRange = SummaryExport.getDataCollectionDateRange(activity);

            String messageBody = activity.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 += activity.getString(R.string.export_message_text_file_attached);
            } else {
                sendIntent.setType("text/plain");
            }
            messageBody += reportSummary;
            sendIntent.putExtra(Intent.EXTRA_TEXT, messageBody);

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

        @Override
        protected void onPostExecute(File result) {
            Log.v(TAG, "onPostExecute");
            // Show a toast if we failed to export a file.
            if (fileExport != null && result == null)
                Toast.makeText(activity, R.string.export_error_sdcard_unmounted, Toast.LENGTH_LONG).show();
            super.onPostExecute(result);
        }
    }.execute();
}

From source file:org.exoplatform.shareextension.ShareActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    setContentView(R.layout.share_extension_activity);

    loadingIndicator = (ProgressBar) findViewById(R.id.share_progress_indicator);
    mainButton = (Button) findViewById(R.id.share_button);
    mainButton.setTag(R.attr.share_button_type_post);
    online = false;/* w ww  . j a  v  a  2  s.c  om*/
    postInfo = new SocialPostInfo();

    if (isIntentCorrect()) {
        Intent intent = getIntent();
        String type = intent.getType();
        if ("text/plain".equals(type)) {
            // The share does not contain an attachment
            // TODO extract the link info - MOB-1866
            postInfo.postMessage = intent.getStringExtra(Intent.EXTRA_TEXT);
        } else {
            // The share contains an attachment
            if (mMultiFlag) {
                mAttachmentUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
            } else {
                Uri contentUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
                if (contentUri != null) {
                    mAttachmentUris = new ArrayList<Uri>();
                    mAttachmentUris.add(contentUri);
                }
                if (Log.LOGD) {
                    Log.d(LOG_TAG, "Number of files to share: ", mAttachmentUris.size());
                }
            }
            prepareAttachmentsAsync();
        }

        init();

        // Create and display the composer, aka ComposeFragment
        ComposeFragment composer = ComposeFragment.getFragment();
        openFragment(composer, ComposeFragment.COMPOSE_FRAGMENT, Anim.NO_ANIM);
    } else {
        // We're not supposed to reach this activity by anything else than an
        // ACTION_SEND intent
        finish();
    }

}

From source file:com.github.akinaru.hcidebugger.activity.BaseActivity.java

protected void setSharedIntent() {
    File sharedFile = new File(mBtSnoopFilePath);

    String object = "HCI report " + timestampFormat.format(new Date().getTime());

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, object);
    intent.putExtra(Intent.EXTRA_TEXT, object);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(sharedFile));

    mShareActionProvider.setShareIntent(intent);
}

From source file:com.irccloud.android.activity.ShareChooserActivity.java

@Override
protected void onResume() {
    super.onResume();
    IRCCloudApplication.getInstance().onResume(this);
    String session = getSharedPreferences("prefs", 0).getString("session_key", "");
    if (session.length() > 0) {
        if (conn.getState() == NetworkConnection.STATE_DISCONNECTED
                || conn.getState() == NetworkConnection.STATE_DISCONNECTING) {
            conn.connect();/*from ww w. j ava 2 s .  com*/
        } else {
            connecting.setVisibility(View.GONE);
            buffersList.setVisibility(View.VISIBLE);
        }
        if (getIntent() != null && getIntent().hasExtra(Intent.EXTRA_STREAM)) {
            mUri = MainActivity.makeTempCopy((Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM), this);
        } else {
            mUri = null;
        }
        if (getIntent() != null && getIntent().hasExtra("bid")) {
            onBufferSelected(getIntent().getIntExtra("bid", -1));
        }
    } else {
        Toast.makeText(this, "You must login to the IRCCloud app before sharing", Toast.LENGTH_SHORT).show();
        finish();
    }
}

From source file:com.theelix.libreexplorer.ActionModeCallback.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    SparseBooleanArray checkedArray = listView.getCheckedItemPositions();
    final List<File> selectedFiles = new ArrayList<>();
    final ArrayList<Uri> selectedUris = new ArrayList<>();
    for (int i = 0; i < listView.getCount(); i++) {
        if (checkedArray.get(i)) {
            selectedFiles.add((File) listView.getItemAtPosition(i));
            selectedUris.add(android.net.Uri.fromFile((File) listView.getItemAtPosition(i)));
        }/* w w w. j  ava  2 s .c o m*/
    }

    switch (item.getItemId()) {
    case R.id.toolbar_menu_copy:
        FileManager.prepareCopy(selectedFiles.toArray(new File[selectedFiles.size()]));
        break;
    case R.id.toolbar_menu_cut:
        FileManager.prepareCut(selectedFiles.toArray(new File[selectedFiles.size()]));
        break;
    case R.id.toolbar_menu_delete:
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        if (selectedFiles.size() > 1) {
            builder.setMessage(mContext.getString(R.string.delete_dialog_multiple) + " " + selectedFiles.size()
                    + " " + mContext.getString(R.string.delete_dialog_items) + "?");
        } else
            builder.setMessage(mContext.getString(R.string.delete_dialog_single));

        builder.setPositiveButton(mContext.getString(R.string.dialog_ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        DeleteTask task = new DeleteTask(mContext,
                                selectedFiles.toArray(new File[selectedFiles.size()]));
                        task.execute();

                    }
                });
        builder.setNegativeButton(mContext.getString(R.string.dialog_cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        builder.show();
        break;
    case R.id.toolbar_menu_rename:
        DialogFragment renameDialog = new RenameDialog();
        ((RenameDialog) renameDialog).setSelectedFiles(selectedFiles.toArray());
        renameDialog.show(((FileManagerActivity) mContext).getSupportFragmentManager(), "rename_dialog");
        break;
    case R.id.toolbar_menu_details:
        DialogFragment detailsDialog = new DetailsDialog();
        ((DetailsDialog) detailsDialog).setTargetFile(selectedFiles.get(0));
        detailsDialog.show(((FileManagerActivity) mContext).getSupportFragmentManager(), "details_dialog");
        break;
    case R.id.toolbar_menu_share:
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, selectedUris);
        shareIntent.setType("*/*");
        mContext.startActivity(Intent.createChooser(shareIntent, "Share to..."));
        break;

    }
    mode.finish();
    return true;
}