Example usage for android.content Intent ACTION_SEND

List of usage examples for android.content Intent ACTION_SEND

Introduction

In this page you can find the example usage for android.content Intent ACTION_SEND.

Prototype

String ACTION_SEND

To view the source code for android.content Intent ACTION_SEND.

Click Source Link

Document

Activity Action: Deliver some data to someone else.

Usage

From source file:com.Bhailal_Chauhan.retailapp.view.fragment.ContactUsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.frag_about, container, false);

    getActivity().setTitle("Contact Us");

    mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar);
    if (mToolbar != null) {
        ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar);
    }/*from  ww w. j a  v a 2  s  .  com*/

    if (mToolbar != null) {
        ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mToolbar.setNavigationIcon(R.drawable.ic_drawer);

    }

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START);
        }
    });

    mToolbar.setTitleTextColor(Color.WHITE);

    rootView.findViewById(R.id.locations).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });

    rootView.findViewById(R.id.contact_num).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent callIntent = new Intent(Intent.ACTION_DIAL);
            callIntent.setData(Uri.parse("tel:" + "8347337366"));
            startActivity(callIntent);

        }
    });

    rootView.setFocusableInTouchMode(true);
    rootView.requestFocus();
    rootView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {

                Utils.switchContent(R.id.frag_container, Utils.HOME_FRAGMENT,
                        ((ECartHomeActivity) (getContext())), AnimationType.SLIDE_UP);

            }
            return true;
        }
    });

    rootView.findViewById(R.id.site_dev).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://bhailalchauhan.com/"));
            startActivity(browserIntent);

        }
    });

    rootView.findViewById(R.id.email).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("text/plain");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "hibhailal458@gmail.com" });
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There");
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here");

            emailIntent.setType("message/rfc822");

            try {
                startActivity(Intent.createChooser(emailIntent, "Send email using..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getActivity(), "No email clients installed.", Toast.LENGTH_SHORT).show();
            }

        }
    });

    return rootView;
}

From source file:com.hybris.mobile.activity.AbstractProductDetailActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean handled = super.onOptionsItemSelected(item);
    if (!handled) {
        // Put custom menu items handlers here
        switch (item.getItemId()) {

        // NFC writing is for debug use only 
        case R.id.write_tag:
            if (NFCUtil.canNFC(this)) {
                Intent writeIntent = new Intent(this, NFCWriteActivity.class);
                NdefMessage msg = getNDEF(mProduct.getCode());
                writeIntent.putExtra(NFCWriteActivity.NDEF_MESSAGE, msg);
                startActivity(writeIntent);
            } else {
                Toast.makeText(this, R.string.error_nfc_not_supported, Toast.LENGTH_LONG).show();
            }/*from w  w  w.  j  ava  2  s . com*/
            return true;
        case R.id.share:

            try {
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT, mProduct.getName() + " - "
                        + getString(R.string.nfc_url, URLEncoder.encode(mProduct.getCode(), "UTF-8")));
                sendIntent.setType("text/plain");
                startActivity(Intent.createChooser(sendIntent, getString(R.string.share_dialog_title)));
            } catch (UnsupportedEncodingException e) {
                LoggingUtils.e(LOG_TAG,
                        "Error trying to encode product code to UTF-8. " + e.getLocalizedMessage(),
                        Hybris.getAppContext());
            }

            return true;
        default:
            return false;
        }
    }
    return handled;
}

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 w w  w. j  a  va 2 s  . c  o  m*/
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:codepath.watsiapp.utils.Util.java

public static void startShareIntent(Activity activity, ShareableItem patient) {
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_TEXT, patient.getShareableUrl());
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Fund Treatment");
    activity.startActivity(Intent.createChooser(shareIntent, "Share Story"));
}

From source file:atv.com.project.monkeylivetv.Activity.MainActivity.java

private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, "http://monkeylivetv.com");
    return shareIntent;
}

From source file:com.elkriefy.android.apps.chubbytabby.activity.MainActivity.java

private PendingIntent createPendingShareIntent() {
    Intent actionIntent = new Intent(Intent.ACTION_SEND);
    actionIntent.setType("text/html");
    actionIntent.putExtra(Intent.EXTRA_TEXT, "This is the Chubby Bunny Challenge/n" + URL);
    return PendingIntent.getActivity(getApplicationContext(), 0, actionIntent, 0);
}

From source file:com.bringcommunications.etherpay.ReceiveActivity.java

private void do_share_guts() {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    qr_bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

    String path = null;/*ww w  . j a va 2 s .co m*/
    try {
        path = MediaStore.Images.Media.insertImage(getContentResolver(), qr_bitmap, "QR Code", null);
        if (path == null) {
            //turns out there's an Android bug, where it happens when the user hasn't taken a photo on the device before (i.e. gallery is empty
            //and hasn't been initialized.). The workaround is to initialize the photo directory manually:
            File sdcard = Environment.getExternalStorageDirectory();
            if (sdcard != null) {
                File mediaDir = new File(sdcard, "DCIM/Camera");
                if (!mediaDir.exists())
                    mediaDir.mkdirs();
            }
            path = MediaStore.Images.Media.insertImage(getContentResolver(), qr_bitmap, "QR Code", null);
        }
    } catch (Exception e) {
    }
    if (path == null) {
        String msg = getResources().getString(R.string.receive_err_no_media_access_msg);
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        return;
    }

    Uri imageUri = Uri.parse(path);
    share.putExtra(Intent.EXTRA_STREAM, imageUri);
    if (show_private)
        share.putExtra(Intent.EXTRA_TEXT, private_key);
    else
        share.putExtra(Intent.EXTRA_TEXT, acct_addr);
    try {
        startActivity(Intent.createChooser(share, "Select"));
    } catch (android.content.ActivityNotFoundException ex) {
        ex.printStackTrace();
    }
}

From source file:com.anysoftkeyboard.ui.SendBugReportUiActivity.java

public void onSendCrashReport(View v) {
    String[] recipients = new String[] { BuildConfig.CRASH_REPORT_EMAIL_ADDRESS };

    Intent sendMail = new Intent();
    sendMail.setAction(Intent.ACTION_SEND);
    sendMail.setType("plain/text");
    sendMail.putExtra(Intent.EXTRA_EMAIL, recipients);
    sendMail.putExtra(Intent.EXTRA_SUBJECT, getText(R.string.ime_crashed_title));
    sendMail.putExtra(Intent.EXTRA_TEXT, mCrashReportDetails.crashReportText);

    try {//from w  ww  .ja  v a  2 s.  c  o m
        Intent sender = Intent.createChooser(sendMail, getString(R.string.ime_crashed_intent_selector_title));
        sender.putExtra(Intent.EXTRA_EMAIL, sendMail.getStringArrayExtra(Intent.EXTRA_EMAIL));
        sender.putExtra(Intent.EXTRA_SUBJECT, sendMail.getStringExtra(Intent.EXTRA_SUBJECT));
        sender.putExtra(Intent.EXTRA_TEXT, mCrashReportDetails.crashReportText);

        Log.i(TAG, "Will send crash report using " + sender);
        startActivity(sender);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getApplicationContext(), "Unable to send bug report via e-mail!", Toast.LENGTH_LONG)
                .show();
    }

    finish();
}

From source file:com.bangz.shotrecorder.RecordDetailActivity.java

private void setShareIntent() {

    if (mShareActionProvider != null) {

        final TextView viewNumber = (TextView) findViewById(R.id.txtNumber);
        String strnumber = viewNumber.getText().toString();

        final TextView viewTime = (TextView) findViewById(R.id.txtTime);
        String strTime = viewTime.getText().toString();

        final TextView viewDate = (TextView) findViewById(R.id.txtDate);
        String strDate = viewDate.getText().toString();

        final TextView viewdescription = (TextView) findViewById(R.id.txtDescription);
        String strDescription = viewdescription.getText().toString();

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        String strcontent = String.format(getResources().getString(R.string.share_content), strDescription,
                strnumber, strTime, strDate);
        intent.putExtra(Intent.EXTRA_TEXT, strcontent);
        mShareActionProvider.setShareIntent(intent);
    }//  www .ja v a2  s .c o  m

}

From source file:com.vladstirbu.cordova.CDVInstagramVideoPlugin.java

private void share(String videoUrl, String captionString) {
    if (videoUrl != null && videoUrl.length() > 0) {

        this.webView.loadUrl("javascript:console.log('processing " + videoUrl + "');");

        byte[] videoData = null;

        try {/*w  w w.j  a va  2  s.c  o m*/

            URL url = new URL(videoUrl);

            URLConnection ucon = url.openConnection();
            InputStream is = ucon.getInputStream();
            videoData = new byte[is.available()];
            is.read(videoData);
            is.close();
        } catch (Exception e) {
            this.webView.loadUrl("javascript:console.log('" + e.getMessage() + "');");
            e.printStackTrace();
        }

        File file = null;
        FileOutputStream os = null;

        File parentDir = this.webView.getContext().getExternalFilesDir(null);
        File[] oldVideos = parentDir.listFiles(OLD_IMAGE_FILTER);
        for (File oldVideo : oldVideos) {
            oldVideo.delete();
        }

        try {
            file = File.createTempFile("instagram_video", ".mp4", parentDir);
            os = new FileOutputStream(file, true);
        } catch (Exception e) {
            this.webView.loadUrl("javascript:console.log('" + e.getMessage() + "');");
            e.printStackTrace();
        }

        try {
            os.write(videoData);
            os.flush();
            os.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("video/mp4");

        //File media = new File(file);
        //Uri uri = Uri.fromFile(media);

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

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

        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file));
        shareIntent.putExtra(Intent.EXTRA_TEXT, captionString);
        shareIntent.setPackage("com.instagram.android");

        this.cordova.startActivityForResult((CordovaPlugin) this, shareIntent, 12345);

    } else {
        this.cbContext.error("Expected one non-empty string argument.");
    }
}