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.jwetherell.quick_response_code.EncoderActivity.java

public void OnClickShare(View view) {
    Statistics.getInstance(EncoderActivity.this).click();

    String message = "";
    message += "\n" + "Nombre Wifi: " + ssidFull;
    message += "\n" + "Clave Wifi: " + pskFull;

    switch (typeShare) {
    case 0: //text

        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, message);
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, "enviar texto"));

        //         typeShare++;
        break;//from   w  w w.j  a  v a  2  s . com

    case 1:
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(viewCode));
        shareIntent.setType("image/jpeg");
        startActivity(Intent.createChooser(shareIntent, "enviar imagen"));

        //         typeShare++;
        break;

    case 2:

        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("*/*");
        share.putExtra(Intent.EXTRA_TEXT, message);
        share.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(viewCode));
        startActivity(Intent.createChooser(share, "Enviar datos de Mi Wifi"));

        //         typeShare = 0;
        break;

    default:
        break;
    }

}

From source file:com.hector.invoice.views.TabExportInvoiceOrder.java

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    if (v == btBack) {
        // return to main menu view
        this.onBackPressed();
    } else if (v == btEmail) {
        String filelocation = "";
        if (currentScreenIndex == Constants.TAB_EXPORT_RECHNUNG) {
            filelocation = ExternalStorage.getFilePDFPath(InvoiceInfo.getInstance().getAppContext())
                    .getAbsolutePath() + "/" + this.fileNamePDF_R;
        } else if (currentScreenIndex == Constants.TAB_EXPORT_LIEFERSCHEIN) {
            filelocation = ExternalStorage.getFilePDFPath(InvoiceInfo.getInstance().getAppContext())
                    .getAbsolutePath() + "/" + this.fileNamePDF_L;
        } else if (currentScreenIndex == Constants.TAB_EXPORT_ANGEBOT) {
            filelocation = ExternalStorage.getFilePDFPath(InvoiceInfo.getInstance().getAppContext())
                    .getAbsolutePath() + "/" + this.fileNamePDF_A;
        }//www.  j  a va  2s. com

        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("application/pdf");
        String to[] = new String[] { "@email.com" };
        sharingIntent.putExtra(Intent.EXTRA_EMAIL, to);
        Uri uri = Uri.parse("file://" + filelocation);
        sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
        startActivity(Intent.createChooser(sharingIntent, "Send email"));
    }
}

From source file:com.swisscom.safeconnect.activity.DashboardActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_show_log:
        Intent logIntent = new Intent(this, LogActivity.class);
        startActivity(logIntent);//from  ww  w .  j a  v a 2 s .  com
        return true;
    case R.id.menu_send_log:
        File log = Logger.saveLogs(this);
        File charonlog = new File(getFilesDir(), CharonVpnService.LOG_FILE);

        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "manuel.cianci1@swisscom.com" });
        intent.putExtra(Intent.EXTRA_SUBJECT, "PipeOfTrust LogFiles");
        intent.setType("text/plain");

        ArrayList<Uri> files = new ArrayList<Uri>();
        if (charonlog.exists() && charonlog.length() > 0) {
            files.add(LogContentProvider.createContentUri());
        }
        if (log.exists() && log.length() > 0) {
            files.add(Uri.fromFile(log));
        }
        if (files.size() == 0) {
            Toast.makeText(this, "Log is empty!", Toast.LENGTH_SHORT).show();
            return true;
        }

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
        startActivity(Intent.createChooser(intent, getString(R.string.send_log)));
        return true;
    case R.id.menu_change_num:
        if (mService.getState() == VpnStateService.State.CONNECTED) {
            mService.disconnect();
        }
        intent = new Intent(this, RegistrationActivity.class);
        intent.putExtra(RegistrationActivity.FORCE_ACTIVITY, true);
        startActivity(intent);
        finish();
        return true;
    case R.id.menu_help:
        startActivity(new Intent(this, FaqActivity.class));
        return true;
    case R.id.menu_settings:
        Intent settingsIntent = new Intent(this, SettingsActivity.class);
        startActivity(settingsIntent);
        return true;
    case R.id.menu_share:
        share();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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

public static void actionSendDocumentsToAlfresco(Fragment fr, List<File> files) {
    if (files.size() == 1) {
        actionSendDocumentToAlfresco(fr.getActivity(), files.get(0));
        return;/*from  ww w .ja  v  a  2  s .co  m*/
    }

    try {
        Intent i = new Intent(fr.getActivity(), PublicDispatcherActivity.class);
        i.setAction(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(i);
    } catch (ActivityNotFoundException e) {
        MessengerManager.showToast(fr.getActivity(), R.string.error_unable_share_content);
    }
}

From source file:net.gerosyab.dailylog.activity.MainActivity.java

private void exportCategory(final long id) {

    //?? ? ?? csv  
    //? ?? ?? /*w  w w.j ava2s. c  o m*/
    // ? ?  ? ? 
    Category category = categories.get((int) id);

    ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setTitle("Exporting data [" + category.getName() + "]");
    progressDialog.show();

    String filename = category.getName() + "" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
            + ".data";
    FileOutputStream outputStream = null;
    File resultFilePath = null;
    File resultFile = null;
    CSVWriter cw = null;

    try {
        resultFile = new File(context.getCacheDir(), filename);

        outputStream = new FileOutputStream(resultFile.getAbsolutePath());
        //            cw = new CSVWriter(new OutputStreamWriter(outputStream, "UTF-8"),'\t', '"');
        cw = new CSVWriter(new OutputStreamWriter(outputStream, "UTF-8"), ',', '"');

        // Export Data
        String[] metaDataStr = { "Version:" + AppDatabase.VERSION, "Name:" + category.getName(),
                "Unit:" + category.getUnit(), "Type:" + category.getRecordType(),
                "DefaultValue:" + category.getDefaultValue(),
                "Columns:date(yyyy-MM-dd 24HH:mm:ss)/value(boolean|numeric|string)" };
        cw.writeNext(metaDataStr);

        List<Record> records = category.getRecordsOrderByDateAscending(realm);
        for (Record record : records) {
            String value = null;
            if (category.getRecordType() == StaticData.RECORD_TYPE_BOOLEAN) {
                value = "true";
            } else if (category.getRecordType() == StaticData.RECORD_TYPE_NUMBER) {
                value = "" + record.getNumber();
            } else if (category.getRecordType() == StaticData.RECORD_TYPE_MEMO) {
                value = record.getString();
            }
            String[] s = { record.getDateString(StaticData.fmtForBackup), value };
            cw.writeNext(s);
        }

        cw.close();
        outputStream.close();

        progressDialog.dismiss();

        Uri fileUri = FileProvider.getUriForFile(context, "net.gerosyab.dailylog.fileprovider", resultFile);

        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
        shareIntent.setType("text/plain");

        startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));

    } catch (UnsupportedEncodingException e) {
        Log.e("DailyLog", e.getMessage());
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        Log.e("DailyLog", e.getMessage());
        e.printStackTrace();
    } catch (Exception e) {
        Log.e("DailyLog", e.getMessage());
        e.printStackTrace();
    } finally {
        progressDialog.dismiss();
    }
}

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

/**
 * Share the videos selected//w  w w. ja  v a 2  s .co m
 *
 * @param position Integer value representing the position of the video to be shared
 * @see #shareVideos(ArrayList positions)
 */
private void shareVideo(int position) {
    Uri fileUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider",
            videos.get(position).getFile());

    Intent Shareintent = new Intent().setAction(Intent.ACTION_SEND).setType("video/*")
            .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION).putExtra(Intent.EXTRA_STREAM, fileUri);
    context.startActivity(
            Intent.createChooser(Shareintent, context.getString(R.string.share_intent_notification_title)));
}

From source file:co.dilaver.quoter.activities.ShareActivity.java

private void save() {

    previewLayout.setDrawingCacheEnabled(true);
    previewLayout.buildDrawingCache();/*from  ww  w. j av a 2  s .c  o  m*/
    Bitmap bmp = Bitmap.createBitmap(previewLayout.getDrawingCache());
    previewLayout.setDrawingCacheEnabled(false);

    ContextWrapper cw = new ContextWrapper(this);
    File directory = cw.getExternalFilesDir(null);
    if (!directory.exists()) {
        directory.mkdir();
    }
    File image = new File(directory, "image.jpg");

    FileOutputStream fos;
    try {
        fos = new FileOutputStream(image);
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.close();
    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
    }

    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + image.getAbsolutePath()));
    shareIntent.setType("image/jpeg");
    startActivity(Intent.createChooser(shareIntent, getString(R.string.str_ShareWith)));
}

From source file:com.agustinprats.myhrv.MainActivity.java

protected void sendFileByEmail(File file) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "eladfein@gmail.com" });
    intent.putExtra(Intent.EXTRA_SUBJECT, "Testing result of HRV bluetooth monitor");
    intent.putExtra(Intent.EXTRA_TEXT, "see files attached");
    Uri uri = Uri.fromFile(file);// w  w  w. j a va 2  s .c  om

    intent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(Intent.createChooser(intent, "Send email..."));

}

From source file:com.jecelyin.editor.v2.ui.MainActivity.java

private boolean processIntentImpl() throws Throwable {
    Intent intent = getIntent();/*  ww  w . j a  v  a 2  s  . c o  m*/
    L.d("intent=" + intent);
    if (intent == null)
        return true; //pass hint

    String action = intent.getAction();
    // action == null if change theme
    if (action == null || Intent.ACTION_MAIN.equals(action)) {
        return true;
    }

    if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)) {
        if (intent.getScheme().equals("content")) {
            InputStream attachment = getContentResolver().openInputStream(intent.getData());
            String text = IOUtils.toString(attachment);
            openText(text);
            return true;
        } else if (intent.getScheme().equals("file")) {
            Uri mUri = intent.getData();
            String file = mUri != null ? mUri.getPath() : null;
            if (!TextUtils.isEmpty(file)) {
                openFile(file);
                return true;
            }
        }

    } else if (Intent.ACTION_SEND.equals(action) && intent.getExtras() != null) {
        Bundle extras = intent.getExtras();
        CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT);

        if (text != null) {
            openText(text);
            return true;
        } else {
            Object stream = extras.get(Intent.EXTRA_STREAM);
            if (stream != null && stream instanceof Uri) {
                openFile(((Uri) stream).getPath());
                return true;
            }
        }
    }

    return false;
}

From source file:com.dycody.android.idealnote.MainActivity.java

/**
 * Notes sharing/*  w w  w  .j  a v a  2  s . c  o  m*/
 */
public void shareNote(Note note) {

    String titleText = note.getTitle();

    String contentText = titleText + System.getProperty("line.separator") + note.getContent();

    Intent shareIntent = new Intent();
    // Prepare sharing intent with only text
    if (note.getAttachmentsList().size() == 0) {
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");

        // Intent with single image attachment
    } else if (note.getAttachmentsList().size() == 1) {
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType(note.getAttachmentsList().get(0).getMime_type());
        shareIntent.putExtra(Intent.EXTRA_STREAM, note.getAttachmentsList().get(0).getUri());

        // Intent with multiple images
    } else if (note.getAttachmentsList().size() > 1) {
        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<>();
        // A check to decide the mime type of attachments to share is done here
        HashMap<String, Boolean> mimeTypes = new HashMap<>();
        for (Attachment attachment : note.getAttachmentsList()) {
            uris.add(attachment.getUri());
            mimeTypes.put(attachment.getMime_type(), true);
        }
        // If many mime types are present a general type is assigned to intent
        if (mimeTypes.size() > 1) {
            shareIntent.setType("*/*");
        } else {
            shareIntent.setType((String) mimeTypes.keySet().toArray()[0]);
        }

        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    }
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
    shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);

    startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.share_message_chooser)));
}