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:de.baumann.hhsmoodle.fragmentsMain.FragmentBrowser.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {

    case R.id.action_help:
        helper_main.switchToActivity(getActivity(), FragmentBrowser_Help.class, false);
        return true;

    case R.id.action_bookmark:
        helper_main.switchToActivity(getActivity(), Popup_bookmarks.class, false);
        return true;

    case R.id.action_saveBookmark:

        final Bookmarks_DbAdapter db = new Bookmarks_DbAdapter(getActivity());
        db.open();/*  w  w  w  .jav  a  2 s  .  co  m*/

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);

        final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
        edit_title.setHint(R.string.bookmark_edit_title);
        edit_title.setText(mWebView.getTitle());

        builder.setView(dialogView);
        builder.setTitle(R.string.bookmark_edit_title);
        builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {

            }
        });
        builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });

        final AlertDialog dialog2 = builder.create();
        // Display the custom alert dialog on interface
        dialog2.show();
        helper_main.showKeyboard(getActivity(), edit_title);

        dialog2.getButton(android.app.AlertDialog.BUTTON_POSITIVE)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //Do stuff, possibly set wantToCloseDialog to true then...
                        String inputTag = edit_title.getText().toString().trim();

                        if (db.isExist(mWebView.getUrl())) {
                            Snackbar.make(edit_title, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG)
                                    .show();
                        } else {
                            db.insert(inputTag, mWebView.getUrl(), "04", "", createDate());
                            dialog2.dismiss();
                            Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show();
                        }
                    }
                });

        return true;

    case R.id.menu_share_screenshot:
        screenshot();

        if (shareFile.exists()) {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("image/png");
            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
            sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
            Uri bmpUri = Uri.fromFile(shareFile);
            sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
            startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot))));
        }
        return true;

    case R.id.menu_save_screenshot:
        screenshot();
        return true;

    case R.id.menu_share_link:
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
        sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
        startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link))));
        return true;

    case R.id.menu_share_link_browser:
        String url = mWebView.getUrl();
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        getActivity().startActivity(intent);
        return true;

    case R.id.menu_share_link_copy:
        String url2 = mWebView.getUrl();
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("text", url2));
        Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_LONG).show();
        return true;
    }
    return false;
}

From source file:com.sentaroh.android.SMBSync.LogFileManagementFragment.java

private void sendLogFile(final AdapterLogFileManagementList lfm_adapter) {
    final String zip_file_name = mGlblParms.settingLogMsgDir + "log.zip";

    int no_of_files = 0;
    for (int i = 0; i < lfm_adapter.getCount(); i++) {
        if (lfm_adapter.getItem(i).isChecked)
            no_of_files++;/* w w  w . j a  v  a2 s . c o m*/
    }
    final String[] file_name = new String[no_of_files];
    int files_pos = 0;
    for (int i = 0; i < lfm_adapter.getCount(); i++) {
        if (lfm_adapter.getItem(i).isChecked) {
            file_name[files_pos] = lfm_adapter.getItem(i).log_file_path;
            files_pos++;
        }
    }
    final ThreadCtrl tc = new ThreadCtrl();
    NotifyEvent ntfy = new NotifyEvent(mContext);
    ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            tc.setDisabled();
        }
    });
    final ProgressBarDialogFragment pbdf = ProgressBarDialogFragment.newInstance(
            mContext.getString(R.string.msgs_log_management_dlg_send_zip_file_creating), "",
            mContext.getString(R.string.msgs_common_dialog_cancel),
            mContext.getString(R.string.msgs_common_dialog_cancel));
    pbdf.showDialog(getFragmentManager(), pbdf, ntfy, true);
    Thread th = new Thread() {
        @Override
        public void run() {
            File lf = new File(zip_file_name);
            lf.delete();
            MiscUtil.createZipFile(tc, pbdf, zip_file_name, file_name);
            if (tc.isEnabled()) {
                Intent intent = new Intent();
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setAction(Intent.ACTION_SEND);
                //                intent.setType("message/rfc822");  
                //                intent.setType("text/plain");
                intent.setType("application/zip");

                intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(lf));
                mFragment.getActivity().startActivity(intent);
            } else {
                lf.delete();

                MessageDialogFragment mdf = MessageDialogFragment.newInstance(false, "W",
                        mContext.getString(R.string.msgs_log_management_dlg_send_zip_file_cancelled), "");
                mdf.showDialog(mFragment.getFragmentManager(), mdf, null);

            }
            pbdf.dismiss();
        };
    };
    th.start();
}

From source file:com.openerp.addons.messages.MessageComposeActivty.java

/**
 * Handle message intent filter for attachments
 * //w w w .  j a v  a  2s.c o  m
 * @param intent
 */
private void handleIntentFilter(Intent intent) {
    attachments_type.put(ATTACHMENT_TYPE.IMAGE, "image/*");
    attachments_type.put(ATTACHMENT_TYPE.TEXT_FILE, "application/*");

    String action = intent.getAction();
    String type = intent.getType();

    // Single attachment
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        Uri fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        file_uris.add(fileUri);
        handleReceivedFile();
    }

    // Multiple Attachments
    if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        ArrayList<Uri> fileUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        file_uris.addAll(fileUris);
        handleReceivedFile();

    }

    // note.note send as mail
    if (intent.hasExtra("note_body")) {
        EditText edtBody = (EditText) findViewById(R.id.edtMessageBody);
        String body = intent.getExtras().getString("note_body");
        edtBody.setText(HTMLHelper.stringToHtml(body));
        is_note_body = true;
    }

}

From source file:com.murrayc.galaxyzoo.app.SubjectFragment.java

private void updateShareActionIntent() {
    /**/*from ww  w .ja  va  2 s . c  o m*/
     * Initialization and setup of the share intent is done here so that less work is left after the AsyncTask's execution
     */
    if (mShareActionProvider == null) {
        Log.error("updateShareActionIntent(): mShareActionProvider is null.");
        return;
    }

    final Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "A Galaxy Zoo image.");
    //Only useful with ACTION_CHOOSER: shareIntent.putExtra(Intent.EXTRA_TITLE, "Share the Galaxy Zoo image.");

    final String uri = Utils.getTalkUri(getZooniverseId());
    if (!TextUtils.isEmpty(uri)) {
        shareIntent.putExtra(Intent.EXTRA_TEXT, uri);
        shareIntent.setType("text/plain");
    }

    //TODO: This doesn't seem to work, maybe because the other app wouldn't have access to our
    //content provider?
    //shareIntent.putExtra(Intent.EXTRA_STREAM, mUriImageStandard);
    //shareIntent.setType("image/*");

    /**
     * if the image URI is not null, a GetImageBitmapAsyncTask is executed for it, and the returned URI is set as
     * a stream extra on the intent that will be shared, along with an explicit permission for recieving contexts to
     * read the content URI, enabling them to access the generated image.
     */
    if (mUriStandardRemote != null) {
        GetImageBitmapAsyncTask getImageBitmapAsyncTask = new GetImageBitmapAsyncTask() {
            @Override
            protected void onPostExecute(Uri uri) {
                shareIntent.setType("image/*");
                shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                mShareActionProvider.setShareIntent(shareIntent);
            }
        };
        getImageBitmapAsyncTask.execute(mUriStandardRemote);
    }

}

From source file:com.flyingcrop.ScreenCaptureFragment.java

void notifySS(Bitmap bitmap, String date, String dir) {

    File file = new File(dir);

    if (file.exists()) {
        Log.d("FlyingCrop", "O ficheiro a ser partilhado existe");
    } else {// w w  w .j  ava 2  s.c o m
        Log.d("FlyingCrop", "O ficheiro a ser partilhado no existe");
    }

    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/png");
    share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

    PendingIntent i = PendingIntent.getActivity(getActivity(), 0,
            Intent.createChooser(share, getResources().getString(R.string.fragment_share)),
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "image/png");
    PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notif = new Notification.Builder(getActivity()).setContentTitle(date + ".png")
            .setContentText(getResources().getString(R.string.fragment_img_preview))
            .addAction(android.R.drawable.ic_menu_share, getResources().getString(R.string.fragment_share), i)
            .setSmallIcon(com.flyingcrop.R.drawable.ab_ico).setLargeIcon(bitmap)
            .setStyle(new Notification.BigPictureStyle().bigPicture(bitmap)).setContentIntent(pendingIntent)
            .setPriority(Notification.PRIORITY_MAX)

            .build();
    final SharedPreferences settings = getActivity().getSharedPreferences("data", 0);

    NotificationManager notificationManager = (NotificationManager) getActivity()
            .getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(1, notif);

    if (settings.getBoolean("vibration", false)) {
        Vibrator v = (Vibrator) this.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(100);
    }
}

From source file:org.alfresco.mobile.android.application.managers.ActionUtils.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  v  a 2  s.  c  om*/
    }

    try {
        Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<>();
        // 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.getInstance(fr.getActivity()).getMIMEType("text/plain"));
        fr.getActivity()
                .startActivity(Intent.createChooser(i, fr.getActivity().getText(R.string.share_content)));
    } catch (ActivityNotFoundException e) {
        AlfrescoNotificationManager.getInstance(fr.getActivity()).showAlertCrouton(fr.getActivity(),
                R.string.error_unable_share_content);
    }
}

From source file:com.sentaroh.android.TaskAutomation.Log.LogFileManagementFragment.java

private void sendLogFile(final LogFileManagementAdapter lfm_adapter) {
    final String zip_file_name = mGlblParms.envParms.settingLogMsgDir + "log.zip";

    int no_of_files = 0;
    for (int i = 0; i < lfm_adapter.getCount(); i++) {
        if (lfm_adapter.getItem(i).isChecked)
            no_of_files++;/*from ww w.j ava2s  .  co m*/
    }
    final String[] file_name = new String[no_of_files];
    int files_pos = 0;
    for (int i = 0; i < lfm_adapter.getCount(); i++) {
        if (lfm_adapter.getItem(i).isChecked) {
            file_name[files_pos] = lfm_adapter.getItem(i).log_file_path;
            files_pos++;
        }
    }
    final ThreadCtrl tc = new ThreadCtrl();
    NotifyEvent ntfy = new NotifyEvent(mContext);
    ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            tc.setDisable();
        }
    });
    final ProgressBarDialogFragment pbdf = ProgressBarDialogFragment.newInstance(
            mContext.getString(R.string.msgs_log_management_dlg_send_zip_file_creating), "",
            mContext.getString(R.string.msgs_common_dialog_cancel),
            mContext.getString(R.string.msgs_common_dialog_cancel));
    pbdf.showDialog(getFragmentManager(), pbdf, ntfy);
    Thread th = new Thread() {
        @Override
        public void run() {
            File lf = new File(zip_file_name);
            lf.delete();
            MiscUtil.createZipFile(tc, pbdf, zip_file_name, file_name);
            if (tc.isEnable()) {
                Intent intent = new Intent();
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setAction(Intent.ACTION_SEND);
                //                intent.setType("message/rfc822");  
                //                intent.setType("text/plain");
                intent.setType("application/zip");

                intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(lf));
                mFragment.getActivity().startActivity(intent);
            } else {
                lf.delete();

                MessageDialogFragment mdf = MessageDialogFragment.newInstance(false, "W",
                        mContext.getString(R.string.msgs_log_management_dlg_send_zip_file_cancelled), "");
                mdf.showDialog(mFragment.getFragmentManager(), mdf, null);

            }
            pbdf.dismiss();
        };
    };
    th.start();
}

From source file:net.opendasharchive.openarchive.ReviewMediaActivity.java

private void shareMedia() {

    StringBuffer sb = new StringBuffer();
    sb.append("\"").append(mMedia.getTitle()).append("\"").append(' ');
    sb.append(getString(R.string.share_media_text)).append(' ');
    sb.append(mMedia.getServerUrl());/*from   w  ww .ja v a 2 s.c  om*/

    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType(mMedia.getMimeType());
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mMedia.getTitle());
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, sb.toString());

    Uri sharedFileUri = null;
    String mediaPath = mMedia.getOriginalFilePath();
    if (mediaPath.startsWith("content:"))
        sharedFileUri = Uri.parse(mediaPath);
    else
        sharedFileUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider",
                new File(mMedia.getOriginalFilePath()));

    sharingIntent.putExtra(Intent.EXTRA_STREAM, sharedFileUri);

    startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using)));
}

From source file:locationkitapp.locationkit.locationkitapp.MapsActivity.java

private void emailVisitHistory() {
    ArrayList<Uri> uris = new ArrayList<Uri>();
    String filename = String.format(Locale.ENGLISH, "data_%d.csv", System.currentTimeMillis());
    File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    File file = new File(root, filename);
    if (!file.exists()) {
        try {/*from   www.  j a  v a 2 s.  c  o  m*/
            file.createNewFile();
        } catch (IOException e) {
            Log.e(LOG_TAG, "file failed", e);
            return;
        }
    }
    try {
        FileOutputStream os = new FileOutputStream(file);
        os.write(
                "arrival_date,detected_time,visit_id,departure_date,category,subcategory,venue_name,street,city,state,zip,detection_method,latitude,longitude,from_place\n"
                        .getBytes());
        for (Visit v : mVisits) {
            os.write(visitRow(v).getBytes());
        }
        os.close();
    } catch (IOException e) {
        Log.e(LOG_TAG, "ioexception on file", e);
        return;
    }
    uris.add(LKDataManager.EXPORT_DB(this));
    Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "LocationKitApp ");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Visits Recorded by LocationKitApp");
    uris.add(Uri.fromFile(file));
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    startActivity(Intent.createChooser(emailIntent, "Pick an Email provider"));
}