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.ushahidi.android.app.activities.BaseActivity.java

protected void sharePhoto(String path) {

    // TODO: consider bringing in shortlink to session
    Preferences.loadSettings(this);
    final String reportUrl = Preferences.domain;
    final String shareString = getString(R.string.share_template, " ", " " + reportUrl);
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/jpg");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + path));
    intent.putExtra(Intent.EXTRA_TEXT, shareString);
    startActivityForResult(Intent.createChooser(intent, getText(R.string.title_share)), 0);
    setResult(RESULT_OK);/* w  ww  .  j a  v  a  2s  .  c  om*/

}

From source file:de.wikilab.android.friendica01.activity.HomeActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case RQ_SELECT_PHOTO:
        if (resultCode == RESULT_OK) {
            Intent in = new Intent(HomeActivity.this, FriendicaImgUploadActivity.class);
            in.putExtra(Intent.EXTRA_STREAM, data.getData());
            startActivity(in);//  ww w.  j a  v  a 2s  .c  o  m
        }
        break;
    case RQ_TAKE_PHOTO:
        if (resultCode == RESULT_OK) {
            //Log.e("INTENT=",data==null?"NULL":"not null");
            Intent in = new Intent(HomeActivity.this, FriendicaImgUploadActivity.class);
            in.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(takePhotoTarget));
            //in.putExtra(Intent.EXTRA_STREAM, data.getData());
            startActivity(in);
        }
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:in.darbose.classroom.statistics.StatisticsFragment.java

/**
 * Share info through social media//from  ww w  .  j a  va 2  s  .c om
 */
private void sendMail() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("plain/text");
    Uri attachment = Uri.parse("file:///" + PATH_FOLDER + FILE_NAME);
    intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
    intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.takeAttendance));
    intent.putExtra(Intent.EXTRA_STREAM, attachment);
    startActivity(intent);
}

From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java

private void initViews(View view) {
    parentLayout = (RelativeLayout) view.findViewById(R.id.fragment_histogram_parent_relative_layout);
    /*BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 2;/*w w w  .  ja v  a2  s . c  o  m*/
    parentLayout.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.histogram_bg, options)));*/
    settingsRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_settings_relative_layout);
    markRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_mark_relative_layout);
    worldRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_world_relative);
    //        worldRelative.setSelected(true);
    worldRelative.setBackgroundResource(R.drawable.cell_p);
    areaRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_area_relative);
    hoodRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_hood_relative);
    yourResultButton = (Button) view.findViewById(R.id.fragment_histogram_your_result_button);

    contentRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_content_relative);

    RelativeLayout shareRelative = (RelativeLayout) view
            .findViewById(R.id.fragment_histogram_share_button_relative);
    shareRelative.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            GoogleTracker.StarSendEvent(getActivity(), "ui_action", "user_action", "histogram_share");

            Bitmap image = makeSnapshot();

            File pictureFile = getOutputMediaFile();
            try {
                FileOutputStream fos = new FileOutputStream(pictureFile);
                image.compress(Bitmap.CompressFormat.PNG, 90, fos);
                fos.close();

            } catch (Exception e) {

            }

            //            String pathofBmp = Images.Media.insertImage(getActivity().getContentResolver(), makeSnapshot(), "Man Hood App", null);
            //             Uri bmpUri = Uri.parse(pathofBmp);
            Uri bmpUri = Uri.fromFile(pictureFile);
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            emailIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
            emailIntent.setType("image/png");
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Man Hood App");
            getActivity().startActivity(emailIntent);

        }
    });

    polarPlot = (PolarPlot) view.findViewById(R.id.polarPlot);

    thicknessHisto = (Histogram) view.findViewById(R.id.thicknessHisto);
    thicknessHisto.setOrientation(ORIENT.LEFT);
    thicknessHisto.setBackgroundColor(Color.TRANSPARENT);
    lengthHisto = (Histogram) view.findViewById(R.id.lengthHistogram);
    lengthHisto.setOrientation(ORIENT.RIGHT);
    lengthHisto.setBackgroundColor(Color.TRANSPARENT);
    girthHisto = (Histogram) view.findViewById(R.id.girthHistogram);
    girthHisto.setOrientation(ORIENT.BOTTOM);
    girthHisto.setBackgroundColor(Color.TRANSPARENT);

    lengthHisto.setCallBackListener(new HistogramCallBack() {

        @Override
        public void setValueSelectionChangedBlock(Histogram histo, HistogramSelectionState selectionState,
                float value, HistogramBin bin) {
            // TODO Auto-generated method stub
            if (selectionState == HistogramSelectionState.HistogramSelectionStateSelected) {
                histogramSelected = true;

                setNearestUserID(usersData.userIDWithNearestLength(value));

                setSelection(true, girthHisto, usersData.girthOfUserWithID(nearestUserID));
                setSelection(true, thicknessHisto, usersData.thicknessOfUserWithID(nearestUserID));
                //               setSelection(false, lengthHisto, 0.0f);
                setSelection(true, lengthHisto, value);

                setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData);
            } else if (selectionState == HistogramSelectionState.HistogramSelectionStateNotSelected) {
                histogramSelected = false;

                setNearestUserID(null);
                setSelectionForAverage();
                setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData);
            } else if (selectionState == HistogramSelectionState.HistogramSelectionStateDelayedFinish) {

            }

        }
    });

    girthHisto.setCallBackListener(new HistogramCallBack() {

        @Override
        public void setValueSelectionChangedBlock(Histogram histo, HistogramSelectionState selectionState,
                float value, HistogramBin bin) {
            // TODO Auto-generated method stub
            if (selectionState == HistogramSelectionState.HistogramSelectionStateSelected) {
                histogramSelected = true;

                setNearestUserID(usersData.userIDWithNearestGirth(value));

                setSelection(true, lengthHisto, usersData.lengthOfUserWithID(nearestUserID));
                setSelection(true, thicknessHisto, usersData.thicknessOfUserWithID(nearestUserID));
                //               setSelection(false, girthHisto, 0.0f);
                setSelection(true, girthHisto, value);

                setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData);
            } else if (selectionState == HistogramSelectionState.HistogramSelectionStateNotSelected) {
                histogramSelected = false;

                setNearestUserID(null);

                setSelectionForAverage();
                setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData);
            } else if (selectionState == HistogramSelectionState.HistogramSelectionStateDelayedFinish) {

            }

        }
    });

    thicknessHisto.setCallBackListener(new HistogramCallBack() {

        @Override
        public void setValueSelectionChangedBlock(Histogram histo, HistogramSelectionState selectionState,
                float value, HistogramBin bin) {
            // TODO Auto-generated method stub
            if (selectionState == HistogramSelectionState.HistogramSelectionStateSelected) {
                histogramSelected = true;

                setNearestUserID(usersData.userIDWithNearestThickness(value));

                setSelection(true, girthHisto, usersData.girthOfUserWithID(nearestUserID));
                setSelection(true, lengthHisto, usersData.lengthOfUserWithID(nearestUserID));
                //                 setSelection(false, thicknessHisto, 0.0f);
                setSelection(true, thicknessHisto, value);

                setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData);
            } else if (selectionState == HistogramSelectionState.HistogramSelectionStateNotSelected) {
                histogramSelected = false;

                setNearestUserID(null);
                setSelectionForAverage();
                setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData);
            } else if (selectionState == HistogramSelectionState.HistogramSelectionStateDelayedFinish) {

            }

        }
    });

    textBoxTitleLabel = (TextView) view.findViewById(R.id.txtBoxTitle);
    textBoxTitleLabel.setText("AVERAGE");

    layoutSubTitle = (LinearLayout) view.findViewById(R.id.layoutSubTitle);
    layoutSubTitle.setVisibility(View.INVISIBLE);
    textBoxSubtitleLabel = (TextView) view.findViewById(R.id.txtBoxSubTitleLabel);
    textBoxSubtitleValueLabel = (TextView) view.findViewById(R.id.txtBoxSubTitleValue);

    lengthSelectedLabel = (TextView) view.findViewById(R.id.txtlengthselected);
    lengthSelectedLabel.setText("50%");
    lengthTOPLabel = (TextView) view.findViewById(R.id.lengthTOPLabel);

    girthSelectedLabel = (TextView) view.findViewById(R.id.txtgirthselected);
    girthSelectedLabel.setText("50%");
    girthTOPLabel = (TextView) view.findViewById(R.id.girthTOPLabel);

    thicknessSelectedLabel = (TextView) view.findViewById(R.id.txtthicknessselected);
    thicknessSelectedLabel.setText("50%");
    thinkestAtTOPLabel = (TextView) view.findViewById(R.id.thinkestAtTOPLabel);

    curvedSelectedLabel = (TextView) view.findViewById(R.id.txtcurvedselected);
    curvedSelectedLabel.setText("0");

    girthTopLB = (TextView) view.findViewById(R.id.girthTop);
    girthMiddleLB = (TextView) view.findViewById(R.id.girthMiddle);
    girthBottomLB = (TextView) view.findViewById(R.id.girthBottom);

    thicknessTopLB = (TextView) view.findViewById(R.id.thicknessTop);
    thicknessMiddleLB = (TextView) view.findViewById(R.id.thicknessMiddle);
    thicknessBottomLB = (TextView) view.findViewById(R.id.thicknessBottom);

    lengthTopLB = (TextView) view.findViewById(R.id.lengthTop);
    lengthMiddleLB = (TextView) view.findViewById(R.id.lengthMiddle);
    lengthBottomLB = (TextView) view.findViewById(R.id.lengthBottom);

    settingsRelative.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((MainActivity) getActivity()).openSettingsActivity();
        }
    });
    markRelative.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((MainActivity) getActivity()).openCertificateActivity();
        }
    });

    worldRelative.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setSelectedRange(SliceRange.SliceRangeAll);
            updateRangeSwitch();
        }
    });
    areaRelative.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setSelectedRange(SliceRange.SliceRange200);
            updateRangeSwitch();
        }
    });
    hoodRelative.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setSelectedRange(SliceRange.SliceRange20);
            updateRangeSwitch();
        }
    });

    yourResultButton.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub

            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                youTouchDown();
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                youTouchUp();
                //               final Handler handler = new Handler();
                //                handler.postDelayed(new Runnable() {
                //                    @Override
                //                    public void run() {
                //                       youTouchUp();             
                //                    }
                //                }, 2000);
            }

            return true;
        }
    });

    RequestManager.getInstance().checkUser();

    /* in-app billing */
    String base64EncodedPublicKey = LICENSE_KEY;

    // Create the helper, passing it our context and the public key to verify signatures with
    Log.d(TAG, "Creating IAB helper.");
    mHelper = new IabHelper(getActivity(), base64EncodedPublicKey);

    // enable debug logging (for a production application, you should set this to false).
    mHelper.enableDebugLogging(true);

    // Start setup. This is asynchronous and the specified listener
    // will be called once setup completes.
    Log.d(TAG, "Starting setup.");
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            Log.d(TAG, "Setup finished.");

            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up in-app billing: " + result);
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null)
                return;

            // IAB is fully set up. Now, let's get an inventory of stuff we own.
            Log.d(TAG, "Setup successful. Querying inventory.");
            mHelper.queryInventoryAsync(mGotInventoryListener);
        }
    });

}

From source file:com.anysoftkeyboard.ui.dev.DeveloperToolsFragment.java

private void shareFile(File fileToShare, String title, String message) {
    Intent sendMail = new Intent();
    sendMail.setAction(Intent.ACTION_SEND);
    sendMail.setType("plain/text");
    sendMail.putExtra(Intent.EXTRA_SUBJECT, title);
    sendMail.putExtra(Intent.EXTRA_TEXT, message);
    if (fileToShare != null) {
        sendMail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileToShare));
    }/*from   www.  j  a v a 2  s.c o m*/

    try {
        Intent sender = Intent.createChooser(sendMail, "Share");
        sender.putExtra(Intent.EXTRA_SUBJECT, title);
        sender.putExtra(Intent.EXTRA_TEXT, message);
        startActivity(sender);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getActivity().getApplicationContext(), "Unable to send bug report via e-mail!",
                Toast.LENGTH_LONG).show();
    }
}

From source file:com.filemanager.free.fragments.preference_fragments.Preffrag.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceUtils.reset();/* www  . j  a v a 2  s .  c  om*/
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);
    preferences = (com.filemanager.free.activities.Preferences) getActivity();
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    final int th1 = Integer.parseInt(sharedPref.getString("theme", "0"));
    theme = th1 == 2 ? PreferenceUtils.hourOfDay() : th1;
    /*findPreference("donate").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
    @Override
    public boolean onPreferenceClick(Preference preference) {
        ((com.filemanager.free.activities.Preferences) getActivity()).donate();
        return false;
    }
    });*/
    findPreference("columns").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            final String[] sort = getResources().getStringArray(R.array.columns);
            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.title(R.string.gridcolumnno);
            int current = Integer.parseInt(sharedPref.getString("columns", "-1"));
            current = current == -1 ? 0 : current;
            if (current != 0)
                current = current - 1;
            a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    sharedPref.edit().putString("columns", "" + (which != 0 ? sort[which] : "" + -1)).commit();
                    dialog.dismiss();
                    return true;
                }
            });
            a.build().show();
            return true;
        }
    });

    findPreference("theme").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            String[] sort = getResources().getStringArray(R.array.theme);
            int current = Integer.parseInt(sharedPref.getString("theme", "0"));
            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    sharedPref.edit().putString("theme", "" + which).commit();
                    dialog.dismiss();
                    restartPC(getActivity());
                    return true;
                }
            });
            a.title(R.string.theme);
            a.build().show();
            return true;
        }
    });

    final SwitchPreference rootmode = (SwitchPreference) findPreference("rootmode");
    rootmode.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            boolean b = sharedPref.getBoolean("rootmode", false);
            if (b) {
                if (RootTools.isAccessGiven()) {
                    rootmode.setChecked(true);

                } else {
                    rootmode.setChecked(false);

                    Toast.makeText(getActivity(), getResources().getString(R.string.rootfailure),
                            Toast.LENGTH_LONG).show();
                }
            } else {
                rootmode.setChecked(false);

            }
            return false;
        }
    });

    //Directory sort mode
    findPreference("dirontop").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            String[] sort = getResources().getStringArray(R.array.directorysortmode);
            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.title(R.string.directorysort);
            int current = Integer.parseInt(sharedPref.getString("dirontop", "0"));
            a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    sharedPref.edit().putString("dirontop", "" + which).commit();
                    dialog.dismiss();
                    return true;
                }
            });
            a.build().show();
            return true;
        }
    });

    findPreference("sortby").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            String[] sort = getResources().getStringArray(R.array.sortby);
            int current = Integer.parseInt(sharedPref.getString("sortby", "0"));
            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    sharedPref.edit().putString("sortby", "" + which).commit();
                    dialog.dismiss();
                    return true;
                }
            });
            a.title(R.string.sortby);
            a.build().show();
            return true;
        }
    });

    // Feedback
    Preference preference3 = (Preference) findPreference("feedback");
    preference3.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", "hoanghiep8899@gmail.com", null));
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback : File Manager");
            Toast.makeText(getActivity(), getActivity().getFilesDir().getPath(), Toast.LENGTH_SHORT).show();
            File f = new File(getActivity().getExternalFilesDir("internal"), "log.txt");
            if (f.exists()) {
                emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
            }
            startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.feedback)));
            return false;
        }
    });

    // rate
    Preference preference5 = (Preference) findPreference("rate");
    preference5.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent1 = new Intent(Intent.ACTION_VIEW);
            intent1.setData(Uri.parse("market://details?id=com.filemanager.free"));
            try {
                startActivity(intent1);
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
            }
            return false;
        }
    });

    // Colored random color
    final SwitchPreference randomColor = (SwitchPreference) findPreference("random_checkbox");
    randomColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (preferences != null)
                preferences.changed = 1;
            Toast.makeText(getActivity(), R.string.setRandom, Toast.LENGTH_LONG).show();
            return true;
        }
    });
    // Colored navigation bar
    final SwitchPreference colorNavigation = (SwitchPreference) findPreference("colorednavigation");
    colorNavigation.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (preferences != null) {
                preferences.changed = 1;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getResources().getString(R.string.confirm));
            builder.setMessage(getResources().getString(R.string.themeRestart));
            builder.setPositiveButton(getResources().getString(R.string.ok),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            restartPC(getActivity());
                        }
                    });
            builder.setNegativeButton(getResources().getString(R.string.cancel),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
            builder.setCancelable(true);
            builder.show();
            return true;
        }
    });
    if (Build.VERSION.SDK_INT >= 21) {
        colorNavigation.setEnabled(true);
    } else {
        colorNavigation.setEnabled(false);
    }

    findPreference("skin").setOnPreferenceClickListener(this);
    findPreference("fab_skin").setOnPreferenceClickListener(this);
    findPreference("icon_skin").setOnPreferenceClickListener(this);
    findPreference("extractpath").setOnPreferenceClickListener(this);
    findPreference("zippath").setOnPreferenceClickListener(this);
}

From source file:ch.dbrgn.android.simplerepost.activities.RepostActivity.java

private void createInstagramIntent(String type, String mediaPath, String caption) {
    // Create the new Intent using the 'Send' action.
    Intent share = new Intent(Intent.ACTION_SEND);

    // Set the MIME type
    share.setType(type);//from   w w  w .j  a va2 s  .co m

    // Create the URI from the media
    File media = new File(mediaPath);
    Uri uri = Uri.fromFile(media);

    // Add the URI and the caption to the Intent.
    share.putExtra(Intent.EXTRA_STREAM, uri);
    share.putExtra(Intent.EXTRA_TEXT, caption);

    // Broadcast the Intent.
    startActivity(Intent.createChooser(share, "Share to"));
}

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

public static void actionSend(Activity activity, File contentFile) {
    try {/*www . ja  va  2s  .  c  o  m*/
        Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra(Intent.EXTRA_SUBJECT, contentFile.getName());
        i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(contentFile));
        i.setType(MimeTypeManager.getMIMEType(activity, contentFile.getName()));
        activity.startActivity(Intent.createChooser(i, activity.getText(R.string.share_content)));
    } catch (ActivityNotFoundException e) {
        MessengerManager.showToast(activity, R.string.error_unable_share_content);
    }
}

From source file:com.android.mail.browse.AttachmentActionHandler.java

public void shareAttachments(ArrayList<Parcelable> uris) {
    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    intent.setType("image/*");
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

    try {/*from   ww  w .jav a2 s  .  c o  m*/
        mContext.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        // couldn't find activity for SEND_MULTIPLE intent
        LogUtils.e(LOG_TAG, "Couldn't find Activity for intent", e);
    }
}

From source file:org.alfresco.mobile.android.application.managers.ActionUtils.java

public static void actionSend(FragmentActivity activity, File contentFile, String mimetype) {
    try {//w w w  . j a v  a 2 s  .co m
        Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra(Intent.EXTRA_SUBJECT, contentFile.getName());
        i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(contentFile));
        i.setType((TextUtils.isEmpty(mimetype))
                ? MimeTypeManager.getInstance(activity).getMIMEType(contentFile.getName())
                : mimetype);

        if (i.resolveActivity(activity.getPackageManager()) == null) {
            AlfrescoNotificationManager.getInstance(activity).showAlertCrouton(activity,
                    activity.getString(R.string.feature_disable));
            return;
        }

        activity.startActivity(Intent.createChooser(i, activity.getText(R.string.share_content)));
    } catch (ActivityNotFoundException e) {
        AlfrescoNotificationManager.getInstance(activity).showAlertCrouton(activity,
                R.string.error_unable_share_content);
    }
}