Example usage for android.content Intent EXTRA_EMAIL

List of usage examples for android.content Intent EXTRA_EMAIL

Introduction

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

Prototype

String EXTRA_EMAIL

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

Click Source Link

Document

A String[] holding e-mail addresses that should be delivered to.

Usage

From source file:liqui.droid.activity.Base.java

/**
 * Open about dialog.//from w w w  . ja v a  2s  .c o  m
 */
public void openAboutDialog() {
    Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.dlg_about);

    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        String versionName = packageInfo.versionName;
        dialog.setTitle(getResources().getString(R.string.app_name) + " v" + versionName);
    } catch (PackageManager.NameNotFoundException e) {
        dialog.setTitle(getResources().getString(R.string.app_name));
    }

    Button btnByEmail = (Button) dialog.findViewById(R.id.btn_by_email);
    btnByEmail.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_EMAIL,
                    new String[] { getResources().getString(R.string.my_email) });
            sendIntent.setType("message/rfc822");
            startActivity(Intent.createChooser(sendIntent, "Select email application."));
        }
    });

    dialog.show();
}

From source file:net.vivekiyer.GAL.CorporateContactRecordFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    // Get the selected item from the listview adapter
    final KeyValuePair kvp = m_adapter.getItem(info.position);

    switch (item.getItemId()) {
    case MENU_ID_CALL:
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" //$NON-NLS-1$
                + kvp.getValue()));//from  w  ww .  j  av a2 s .c  o  m
        startActivity(intent);
        break;
    case MENU_ID_SMS:
        intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" //$NON-NLS-1$
                + kvp.getValue()));
        startActivity(intent);
        break;
    case MENU_ID_COPY_TO_CLIPBOARD:
        final ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(kvp.getValue());
        Toast.makeText(this.getActivity(), getString(R.string.text_copied_to_clipboard), Toast.LENGTH_SHORT)
                .show();
        break;
    case MENU_ID_EDIT_BEFORE_CALL:
        intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" //$NON-NLS-1$
                + kvp.getValue()));
        startActivity(intent);
        break;
    case MENU_ID_EMAIL:
        intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain"); //$NON-NLS-1$
        intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { kvp.getValue() });
        startActivity(Intent.createChooser(intent, getString(R.string.send_mail)));
        break;
    default:
        return super.onContextItemSelected(item);
    }
    return true;
}

From source file:us.socialgoodworking.mocklocation.MockLocationActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent i;//  www  .j ava 2s. c o m

    switch (item.getItemId()) {
    // Toggle for 'playback' mode...
    case R.id.tap_or_playback:
        onTapOrPlayback();
        break;

    case R.id.record:
        onRecord();
        break;

    case R.id.about:
        i = new Intent(this, AboutActivity.class);
        Logging.debug(TAG, TAG, "onOptionsItemSelected starting About...");
        startActivity(i);
        break;

    case R.id.policy:
        i = new Intent(this, PolicyActivity.class);
        Logging.debug(TAG, TAG, "onOptionsItemSelected starting About...");
        startActivity(i);
        break;

    //          case R.id.legal:
    //               String LicenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
    //               AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(this);
    //               LicenseDialog.setTitle("Legal Notices");
    //               LicenseDialog.setMessage(LicenseInfo);
    //               LicenseDialog.show();
    //               break;

    case R.id.contact_us:
        try {
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                    new String[] { "paul@socialgoodworking.us" });
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "MockLocation Comment");
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                    "We want your input! Let us know what you think...");
            startActivity(Intent.createChooser(emailIntent, "Contact us via:"));
        } catch (Exception ex) {
            Logging.debug(TAG, "onOptionsItemSelected", ex.getMessage());
        }
        break;
    }

    return true;
}

From source file:com.pacoapp.paco.ui.FindExperimentsActivity.java

private void launchEmailPacoTeam() {
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    String aEmailList[] = { getString(R.string.contact_email) };
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.email_subject_paco_feedback));
    emailIntent.setType("plain/text");
    startActivity(emailIntent);//from w  ww .  j  a  v a2s  . c  om
}

From source file:ru.dublgis.androidhelpers.DesktopUtils.java

public static boolean sendEmail(final Context ctx, final String to, final String subject, final String body,
        final String[] attachment, final String authorities) {
    try {/*from   ww  w. j  a  v a 2s. c o  m*/
        final String[] recipients = new String[] { to };

        final Intent intent = new Intent(
                attachment.length > 1 ? Intent.ACTION_SEND_MULTIPLE : Intent.ACTION_SENDTO);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setType("message/rfc822");
        intent.putExtra(Intent.EXTRA_EMAIL, recipients);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, body);

        boolean grant_permissions_workaround = false;
        final ArrayList<Uri> uri = new ArrayList<>();
        if (attachment.length > 0) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                for (final String fileName : attachment) {
                    uri.add(Uri.fromFile(new File(fileName)));
                }
            } else {
                // Android 6+: going the longer route.
                // For more information, please see:
                // http://stackoverflow.com/questions/32981194/android-6-cannot-share-files-anymore
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                grant_permissions_workaround = true;
                for (final String fileName : attachment) {
                    uri.add(FileProvider.getUriForFile(ctx, authorities, new File(fileName)));
                }
            }
            // Should not put array with only one element into intent because of a bug in GMail.
            if (uri.size() == 1) {
                intent.putExtra(Intent.EXTRA_STREAM, uri.get(0));
            } else {
                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uri);
            }
        }

        final IntentResolverInfo mailtoIntentResolvers = new IntentResolverInfo(ctx.getPackageManager());
        mailtoIntentResolvers
                .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", to, null)));

        final Intent chooserIntent;

        if (mailtoIntentResolvers.isEmpty()) {
            chooserIntent = Intent.createChooser(intent, null);
        } else {
            final IntentResolverInfo messageIntentResolvers = new IntentResolverInfo(ctx.getPackageManager());
            messageIntentResolvers
                    .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("sms", "", null)));
            messageIntentResolvers
                    .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mms", "", null)));
            messageIntentResolvers
                    .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("tel", "", null)));

            mailtoIntentResolvers.removeSamePackages(messageIntentResolvers.getResolveInfos());

            final List<Intent> intentList = new ArrayList<>();

            for (final ActivityInfo activityInfo : mailtoIntentResolvers.getResolveInfos()) {
                final String packageName = activityInfo.getPackageName();
                final String name = activityInfo.getName();

                // Some mail clients will not read the URI unless this is done.
                // See here: https://stackoverflow.com/questions/24467696/android-file-provider-permission-denial
                if (grant_permissions_workaround) {
                    for (int i = 0; i < uri.size(); ++i) {
                        try {
                            ctx.grantUriPermission(packageName, uri.get(i),
                                    Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        } catch (final Throwable e) {
                            Log.e(TAG, "grantUriPermission error: ", e);
                        }
                    }
                }

                final Intent cloneIntent = (Intent) intent.clone();
                cloneIntent.setComponent(new ComponentName(packageName, name));
                intentList.add(cloneIntent);
            }

            final Intent targetIntent = intentList.get(0);
            intentList.remove(0);

            chooserIntent = Intent.createChooser(targetIntent, null);
            if (!intentList.isEmpty()) {
                final Intent[] extraIntents = intentList.toArray(new Intent[intentList.size()]);
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
                } else {
                    chooserIntent.putExtra(Intent.EXTRA_ALTERNATE_INTENTS, extraIntents);
                }
            }
        }

        chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        ctx.startActivity(chooserIntent);

        return true;
    } catch (final Throwable exception) {
        Log.e(TAG, "sendEmail exception: ", exception);
        return false;
    }
}

From source file:org.sufficientlysecure.keychain.ui.EncryptFileActivity.java

private Intent createSendIntent(Message message) {
    Intent sendIntent;/*  w w w  . j  av a  2  s.  c  om*/
    // file
    if (mOutputUris.size() == 1) {
        sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_STREAM, mOutputUris.get(0));
    } else {
        sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        sendIntent.putExtra(Intent.EXTRA_STREAM, mOutputUris);
    }
    sendIntent.setType("application/octet-stream");

    if (!isModeSymmetric() && mEncryptionUserIds != null) {
        Set<String> users = new HashSet<String>();
        for (String user : mEncryptionUserIds) {
            String[] userId = KeyRing.splitUserId(user);
            if (userId[1] != null) {
                users.add(userId[1]);
            }
        }
        sendIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()]));
    }
    return sendIntent;
}

From source file:com.mstoyanov.music_lessons.StudentsFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    switch (parent.getId()) {
    case R.id.students_list:
        Cursor cursor = (Cursor) parent.getItemAtPosition(position);
        studentId = cursor.getInt(cursor.getColumnIndex("_id"));
        String firstName = cursor.getString(cursor.getColumnIndex("firstName"));
        String lastName = cursor.getString(cursor.getColumnIndex("lastName"));
        if (dualPane) {
            studentsList.setItemChecked(position, true);
            selectedStudent = position;/*from   w w w.j av  a  2 s.com*/

            selectionArgs[0] = String.valueOf(studentId);

            firstNameLabel.setText("First Name");
            firstNameTextView.setText(firstName);
            lastNameLabel.setText("Last Name");
            lastNameTextView.setText(lastName);

            getLoaderManager().restartLoader(STUDENT_DETAILS_LOADER, null, this);
        } else {
            Intent intent = new Intent(getActivity(), StudentDetailsActivity.class);
            intent.putExtra("STUDENT_ID", studentId);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
        break;
    case R.id.student_details_list:
        Actions action = actions.get(position);
        switch (action.getType()) {
        case Actions.ACTION_CALL:
            Uri callUri = Uri.parse("tel:" + action.getData());
            Intent intent = new Intent(Intent.ACTION_CALL, callUri);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            break;
        case Actions.ACTION_EMAIL:
            intent = new Intent(Intent.ACTION_SEND);
            intent.setType("plain/text");
            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { action.getData() });
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            break;
        case Actions.ACTION_SMS:
            Uri smsUri = Uri.parse("sms:" + action.getData());
            intent = new Intent(Intent.ACTION_VIEW, smsUri);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        default:
            throw new IllegalArgumentException("Invalid action type: " + action.getType());
        }
    default:
        throw new IllegalArgumentException("Invalid parentId: " + parent.getId());
    }
}

From source file:com.openarc.nirmal.mytrack.ContactActivity.java

private void showContactDialog(final Contact contact) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ContactActivity.this);
    View dialogView = getLayoutInflater().inflate(R.layout.dialog_view_contact, null);
    alertDialogBuilder.setView(dialogView);
    ImageView ivClose = (ImageView) dialogView.findViewById(R.id.ivClose);
    ImageView ivBackground = (ImageView) dialogView.findViewById(R.id.ivBackground);
    ImageView civContactImage = (CircleImageView) dialogView.findViewById(R.id.civContactImage);
    TextView tvContactName = (TextView) dialogView.findViewById(R.id.tvContactName);
    TextView tvCallNumber = (TextView) dialogView.findViewById(R.id.tvCallNumber);
    TextView tvMessageNumber = (TextView) dialogView.findViewById(R.id.tvMessageNumber);

    CardView callCardView = (CardView) dialogView.findViewById(R.id.cvCall);
    CardView smsCardView = (CardView) dialogView.findViewById(R.id.cvSMS);
    CardView emailCardView = (CardView) dialogView.findViewById(R.id.cvEmail);

    TextView tvEmail = (TextView) dialogView.findViewById(R.id.tvEmail);
    Picasso.with(ContactActivity.this).load(contact.image).into(ivBackground);
    Picasso.with(ContactActivity.this).load(contact.image).into(civContactImage);
    tvContactName.setText(contact.name);
    tvCallNumber.setText(contact.mobile);
    tvMessageNumber.setText(contact.mobile);
    tvEmail.setText(contact.email);//w ww . j  a  v  a2  s .  com
    final AlertDialog alertDialog = alertDialogBuilder.create();
    ivClose.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                alertDialog.dismiss();
            }
            return false;
        }
    });

    callCardView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!contact.mobile.contentEquals("")) {
                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:" + contact.mobile));
                    if (ActivityCompat.checkSelfPermission(ContactActivity.this,
                            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                        showToast("Cannot Make a Call");
                    } else {
                        startActivity(callIntent);
                        alertDialog.dismiss();
                    }
                } else {
                    showToast("Not a valid mobile");
                }
            }
            return false;
        }
    });

    smsCardView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!contact.mobile.contentEquals("")) {
                    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                    sendIntent.setData(Uri.parse("sms:" + contact.mobile));
                    startActivity(sendIntent);
                    alertDialog.dismiss();
                } else {
                    showToast("Not a valid mobile");
                }
            }
            return false;
        }
    });

    emailCardView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!contact.email.contentEquals("")) {
                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                    emailIntent.setType("plain/text");
                    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { contact.email });
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
                    emailIntent.putExtra(Intent.EXTRA_TEXT, "");
                    startActivity(emailIntent);
                    alertDialog.dismiss();
                } else {
                    showToast("Not a valid email");
                }
            }
            return false;
        }
    });
    alertDialog.show();
}

From source file:dentex.youtube.downloader.utils.Utils.java

public static void offerDevMail(final Context ctx) {
    AlertDialog.Builder adb = new AlertDialog.Builder(ctx);
    adb.setIcon(Utils.selectThemedAlertIcon());
    adb.setTitle(ctx.getString(R.string.ffmpeg_device_not_supported));
    adb.setMessage(ctx.getString(R.string.ffmpeg_support_mail));

    adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            /*//from w w  w  . j  ava  2  s. co m
             * adapted form same source as createEmailOnlyChooserIntent below
             */
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("*/*");

            String content = Utils.getCpuInfo();
            /*File destDir = getActivity().getExternalFilesDir(null); 
            String filename = "cpuInfo.txt";
            try {
             Utils.createLogFile(destDir, filename, content);
             i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(destDir, filename)));*/
            i.putExtra(Intent.EXTRA_EMAIL, new String[] { "samuele.rini76@gmail.com" });
            i.putExtra(Intent.EXTRA_SUBJECT, "YTD: device info report");
            i.putExtra(Intent.EXTRA_TEXT, content);

            ctx.startActivity(createEmailOnlyChooserIntent(ctx, i, ctx.getString(R.string.email_via)));
            /*} catch (IOException e) {
               Log.e(DEBUG_TAG, "IOException on creating cpuInfo Log file ", e);
            }*/
        }
    });

    adb.setNegativeButton(ctx.getString(R.string.dialogs_negative), new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // cancel
        }
    });

    AlertDialog helpDialog = adb.create();
    if (!((Activity) ctx).isFinishing()) {
        helpDialog.show();
    }
}

From source file:ru.neverdark.phototools.azimuth.PluginActivity.java

private void showFeedback() {
    Intent mailIntent = new Intent(Intent.ACTION_SEND);
    mailIntent.setType("plain/text");
    mailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { getString(R.string.author_email) });
    mailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
    startActivity(Intent.createChooser(mailIntent, getString(R.string.chooseEmailApp)));
}