android.net.MailTo Java Examples

The following examples show how to use android.net.MailTo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MailtoWebView.java    From watchpresenter with Apache License 2.0 6 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url.startsWith("mailto:")) {
        final Activity activity = mActivityRef.get();
        if (activity != null) {
            MailTo mt = MailTo.parse(url);
            Intent i = newEmailIntent(activity, mt.getTo(), mt.getSubject(), mt.getBody(), mt.getCc());
            activity.startActivity(i);
            view.reload();
            return true;
        }
    } else {
        view.loadUrl(url);
    }
    return true;
}
 
Example #2
Source File: HelpActivity.java    From android-mrz-reader with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
  if (url.startsWith("file")) {
    // Keep local assets in this WebView.
    return false;
  } else if (url.startsWith("mailto:")) {
    try {
          MailTo mt = MailTo.parse(url);
          Intent i = new Intent(Intent.ACTION_SEND);
          i.setType("message/rfc822");
          i.putExtra(Intent.EXTRA_EMAIL, new String[]{mt.getTo()});
          i.putExtra(Intent.EXTRA_SUBJECT, mt.getSubject());
          context.startActivity(i);
          view.reload();
    }
    catch (ActivityNotFoundException e) {
      Log.w(TAG, "Problem with Intent.ACTION_SEND", e);
              new AlertDialog.Builder(context)
                .setTitle("Contact Info")
                .setMessage( "Please send your feedback to: [email protected]" )
                .setPositiveButton( "Done", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Log.d("AlertDialog", "Positive");
                    }
                })
                .show();
    }
        return true;
  } else {
    // Open external URLs in Browser.
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    return true;
  }
}
 
Example #3
Source File: NewConversationActivity.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleIntent() {
  Intent intent = getIntent();
  String action = intent.getAction();
  if(Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SENDTO.equals(action)) {
    try {
      Uri uri = intent.getData();
      if(uri != null) {
        String scheme = uri.getScheme();
        if(scheme != null && scheme.equals(MAILTO) ) {
          String textToShare = getTextToShare(uri);
          MailTo mailto = MailTo.parse(uri.toString());
          String recipientsList = mailto.getTo();
          if(recipientsList != null && !recipientsList.isEmpty()) {
            String[] recipientsArray = recipientsList.split(",");
            if (recipientsArray.length >= 1) {
              String recipient = recipientsArray[0];
              if (textToShare != null && !textToShare.isEmpty()) {
                getIntent().putExtra(TEXT_EXTRA, textToShare);
              }
              onContactSelected(DcContact.DC_CONTACT_ID_NEW_CONTACT, recipient);
            }
          } else {
            Intent shareIntent = new Intent(this, ShareActivity.class);
            shareIntent.putExtra(Intent.EXTRA_TEXT, textToShare);
            startActivity(shareIntent);
            finish();
          }
        }
      }
    }
    catch(Exception e) {
      Log.e(TAG, "start activity from external 'mailto:' link failed", e);
    }
  }
}
 
Example #4
Source File: TabContextMenuItemDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onAddToContacts(String url) {
    Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
    if (MailTo.isMailTo(url)) {
        intent.putExtra(
                ContactsContract.Intents.Insert.EMAIL, MailTo.parse(url).getTo().split(",")[0]);
    } else if (UrlUtilities.isTelScheme(url)) {
        intent.putExtra(ContactsContract.Intents.Insert.PHONE, UrlUtilities.getTelNumber(url));
    }
    IntentUtils.safeStartActivity(mTab.getActivity(), intent);
}
 
Example #5
Source File: IntentUnit.java    From Ninja with Apache License 2.0 5 votes vote down vote up
public static Intent getEmailIntent(MailTo mailTo) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { mailTo.getTo() });
    intent.putExtra(Intent.EXTRA_TEXT, mailTo.getBody());
    intent.putExtra(Intent.EXTRA_SUBJECT, mailTo.getSubject());
    intent.putExtra(Intent.EXTRA_CC, mailTo.getCc());
    intent.setType(INTENT_TYPE_MESSAGE_RFC822);

    return intent;
}