Example usage for android.content Intent ACTION_SENDTO

List of usage examples for android.content Intent ACTION_SENDTO

Introduction

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

Prototype

String ACTION_SENDTO

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

Click Source Link

Document

Activity Action: Send a message to someone specified by the data.

Usage

From source file:com.example.android.smssample.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Find some views
    mSetDefaultSmsLayout = (RelativeLayout) findViewById(R.id.set_default_sms_layout);
    mSendSmsEditText = (EditText) findViewById(R.id.send_sms_edittext);
    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setEmptyView(findViewById(android.R.id.empty));
    mSendSmsButton = (Button) findViewById(R.id.send_sms_button);
    mSendSmsButton.setOnClickListener(new OnClickListener() {
        @Override//from   w  w w .ja v a2 s.co  m
        public void onClick(View view) {
            sendSms(mSendSmsEditText.getText().toString());
        }
    });

    // Create adapter and set it to our ListView
    final String[] fromFields = new String[] { SmsQuery.PROJECTION[SmsQuery.ADDRESS],
            SmsQuery.PROJECTION[SmsQuery.BODY] };
    final int[] toViews = new int[] { android.R.id.text1, android.R.id.text2 };
    mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, null, fromFields, toViews, 0);
    listView.setAdapter(mAdapter);

    // Placeholder to process incoming SEND/SENDTO intents
    String intentAction = getIntent() == null ? null : getIntent().getAction();
    if (!TextUtils.isEmpty(intentAction)
            && (Intent.ACTION_SENDTO.equals(intentAction) || Intent.ACTION_SEND.equals(intentAction))) {
        // TODO: Handle incoming SEND and SENDTO intents by pre-populating UI components
        Toast.makeText(this, "Handle SEND and SENDTO intents: " + getIntent().getDataString(),
                Toast.LENGTH_SHORT).show();
    }

    // Simple query to show the most recent SMS messages in the inbox
    getSupportLoaderManager().initLoader(SmsQuery.TOKEN, null, this);
}

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

private PendingIntent createPendingEmailIntent() {
    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "example@example.com", null));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
    return PendingIntent.getActivity(getApplicationContext(), 0, emailIntent, 0);
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * Launch Email Intent.//from w w w.j  a  va  2  s.c o  m
 *
 * @param activity context
 * @param address  to send to
 */
public static void launchEmailIntent(Activity activity, String address) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:"));

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address });
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(intent);
    }
}

From source file:com.enadein.carlogbook.ui.AboutFragment.java

public void sendEmail(String subject) {
    Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", getString(R.string.email), null));
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);

    startActivity(Intent.createChooser(intent, "Send Email"));
}

From source file:com.sakisds.icymonitor.activities.AboutActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*from ww w .j ava 2 s. c  om*/
        return (true);
    case R.id.item_github:
        Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://sakisds.github.io/Icy-Monitor/"));
        startActivity(browserIntent);
        return true;
    case R.id.item_contact:
        Uri uri = Uri.parse("mailto:sakisds.s@gmail.com");
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO, uri);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Icy Monitor Feedback");
        startActivity(emailIntent);
        return true;
    }
    return (super.onOptionsItemSelected(item));
}

From source file:de.dev.eth0.rssreader.app.ui.AbstractNavigationDrawerActivity.java

/**
 * Handles clicks on the navigation menu.
 *
 * @param menuItem/*from  ww  w. j av  a 2 s.  co  m*/
 * @return
 */
@Override
public boolean onNavigationItemSelected(final MenuItem menuItem) {
    // update highlighted item in the navigation menu
    final int itemId = menuItem.getItemId();

    // allow some time after closing the drawer before performing real navigation
    // so the user can see what is happening
    drawerLayout.closeDrawers();
    drawerActionHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            //Don't do anything if the item has already been selected
            if (getMenuItemId() != itemId) {
                switch (itemId) {
                case R.id.nav_summaries:
                    startActivity(new Intent(AbstractNavigationDrawerActivity.this, MainActivity.class));
                    break;
                case R.id.nav_bookmarked:
                    startActivity(new Intent(AbstractNavigationDrawerActivity.this, BookmarkedActivity.class));
                    break;
                case R.id.nav_authors:
                    startActivity(new Intent(AbstractNavigationDrawerActivity.this, AuthorsActivity.class));
                    break;
                case R.id.nav_settings:
                    startActivity(new Intent(AbstractNavigationDrawerActivity.this, SettingsActivity.class));
                    break;
                case R.id.nav_feedback:
                    Intent email = new Intent(Intent.ACTION_SENDTO,
                            Uri.fromParts("mailto", Constants.REPORT_EMAIL, null));
                    email.putExtra(Intent.EXTRA_SUBJECT, Constants.FEEDBACK_SUBJECT);
                    startActivity(Intent.createChooser(email, null));
                    break;
                case R.id.nav_about:
                    startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(BuildConfig.ABOUT_URL)));
                    break;
                case R.id.nav_donate:
                    //TODO: add bitcoin option
                    startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(BuildConfig.DONATE_URL)));
                    break;
                default:
                    // ignore
                    break;
                }
            }
        }
    }, DRAWER_CLOSE_DELAY_MS);
    return true;
}

From source file:mobisocial.musubi.ui.EmailUnclaimedMembersActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mHandler = new Handler();
    mIntent = getIntent();/*w w w  . j a  v  a 2s  .c  om*/
    mFeedUri = mIntent.getParcelableExtra(INTENT_EXTRA_FEED_URI);

    final int[] authorities = mIntent.getIntArrayExtra(INTENT_EXTRA_AUTHORITIES);
    final String recipients[] = mIntent.getStringArrayExtra(android.content.Intent.EXTRA_BCC);

    //    for debug 
    //      final String recipients[]={"574632066","640321536"};
    //      authorities[0] = Authority.Facebook.ordinal();

    Fragment memberView = new EmailUnclaimedMembersFragment();

    Bundle args = new Bundle();
    args.putParcelable("feed_uri", mFeedUri);

    memberView.setArguments(args);

    setContentView(R.layout.activity_email_unclaimed_member_list);

    Button sendButton = (Button) findViewById(R.id.send_unclaimed_email);
    Button cancelButton = (Button) findViewById(R.id.cancel_unclaimed_email);

    sendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //TODO: need to support different invitations for different providers
            if (authorities[0] == Authority.Email.ordinal()) {
                final String subject = "You have a new Musubi message!";
                final String body = message + " " + MUSUBI_MARKET_URL;
                Intent send = new Intent(Intent.ACTION_SENDTO);
                StringBuilder recipientsString = new StringBuilder();
                // only add emails
                for (int i = 0; i < recipients.length; i++) {
                    if (authorities[i] == Authority.Email.ordinal()) {
                        recipientsString.append(recipients[i]).append(",");
                    }
                }
                recipientsString.deleteCharAt(recipientsString.length() - 1);
                String uriText;
                uriText = "mailto:" + recipientsString.toString() + "?subject=" + subject + "&body=" + body;
                //TODO: real url encoding?
                uriText = uriText.replace(" ", "%20");
                Uri uri = Uri.parse(uriText);
                send.setData(uri);
                startActivity(Intent.createChooser(send, "Send invitation..."));

                MIdentity[] identities = markAsHasSent(mIntent);
                //let other people in the feed know that spamming is unnecessary
                if (mFeedUri != null) {
                    Obj invitedObj = OutOfBandInvitedObj.from(Arrays.asList(identities).iterator());
                    Helpers.sendToFeed(EmailUnclaimedMembersActivity.this, invitedObj, mFeedUri);
                }

                EmailUnclaimedMembersActivity.this.finish();
            } else if (authorities[0] == Authority.Facebook.ordinal()) {
                Facebook fb = AccountLinkDialog.getFacebookInstance(EmailUnclaimedMembersActivity.this);
                //               AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(fb);
                //
                if (fb.isSessionValid()) {
                    //                   // TODO: batch request in json array. currently facebook limits 50 requests per batch
                    //                   // need to split up it if it's more than 50
                    //                   final String fbmsg = new StringBuilder()
                    //                      .append("message=").append(message)
                    //                      .append("&link=").append(link)
                    //                      .append("&picture=").append(LOGO_PICTURE_URL).toString();
                    //                   
                    //                   JSONArray batchObj = new JSONArray();
                    //                   try {
                    //                      for(String id : recipients) {
                    //                          JSONObject post = new JSONObject();
                    //                          post.put("method", "POST");
                    //                          post.put("relative_url", id+"/feed");
                    //                          post.put("body", fbmsg);
                    //                          batchObj.put(post);
                    //                       }
                    //                   } catch (JSONException e) {
                    //                      Log.e(TAG, e.toString());
                    //                   }
                    //                   Bundle batch = new Bundle();
                    //                   batch.putString("batch", batchObj.toString());
                    //                   asyncRunner.request("/", batch, "POST", new FriendRequestListener(), null);

                    StringBuilder recipientsString = new StringBuilder();
                    // only add fb ids
                    for (int i = 0; i < recipients.length; i++) {
                        if (authorities[i] == Authority.Facebook.ordinal()) {
                            recipientsString.append(recipients[i]).append(",");
                        }
                    }
                    recipientsString.deleteCharAt(recipientsString.length() - 1);
                    Bundle params = new Bundle();
                    params.putString("message", message);
                    params.putString("to", recipientsString.toString());
                    fb.dialog(EmailUnclaimedMembersActivity.this, "apprequests", params,
                            new AppRequestDialogListener());

                }
            }
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //if i say no, i mean NO!
            markAsHasSent(mIntent);
            EmailUnclaimedMembersActivity.this.finish();
        }
    });

    getSupportFragmentManager().beginTransaction().replace(R.id.member_list, memberView).commit();

}

From source file:com.nikhilnayak.games.octoshootar.ui.fragments.AboutFragment.java

private void sendUsAnEmail(int subjectResourceId) {
    final String uriString = getString(R.string.email_us_uri, Uri.encode(getString(R.string.email_us_email)),
            Uri.encode(getString(subjectResourceId)));
    final Uri mailToUri = Uri.parse(uriString);
    Intent sendToIntent = new Intent(Intent.ACTION_SENDTO);
    sendToIntent.setData(mailToUri);/*from w  ww.  j  a  va  2s. c om*/
    startActivity(sendToIntent);
}

From source file:com.github.akinaru.roboticbuttonpusher.menu.MenuUtils.java

/**
 * Execute actions according to selected menu item
 *
 * @param menuItem MenuItem object/*w  w  w.j a  v a  2 s  .co m*/
 * @param mDrawer  navigation drawer
 * @param context  android context
 */
public static void selectDrawerItem(MenuItem menuItem, DrawerLayout mDrawer, Context context,
        final IButtonPusher buttonPusher) {

    switch (menuItem.getItemId()) {
    case R.id.exit_item: {
        if (buttonPusher.giveUpNoPermission()) {
            buttonPusher.disassociate();
        } else {
            buttonPusher.requestPermission();
        }
        break;
    }
    case R.id.password_item: {
        if (buttonPusher != null) {
            if (buttonPusher.giveUpNoPermission()) {
                DevicePasswordDialog dialog = new DevicePasswordDialog(buttonPusher);
                dialog.show();
            } else {
                buttonPusher.requestPermission();
            }
        }
        break;
    }
    case R.id.keys_item: {
        if (buttonPusher != null) {
            if (buttonPusher.giveUpNoPermission()) {
                KeysDialog dialog = new KeysDialog(buttonPusher);
                dialog.show();
            } else {
                buttonPusher.requestPermission();
            }
        }
        break;
    }
    case R.id.message_item: {
        if (buttonPusher != null) {
            if (buttonPusher.giveUpNoPermission()) {
                DeviceMessageDialog dialog = new DeviceMessageDialog(buttonPusher);
                dialog.show();
            } else {
                buttonPusher.requestPermission();
            }
        }
        break;
    }
    case R.id.debug_mode_item: {

        CharSequence[] array = { "enabled", "disabled" };

        int indexCheck = buttonPusher.getDebugMode() ? 0 : 1;

        new AlertDialog.Builder(context).setSingleChoiceItems(array, indexCheck, null)
                .setPositiveButton(buttonPusher.getContext().getResources().getString(R.string.dialog_ok),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.dismiss();
                                int selectedPosition = ((AlertDialog) dialog).getListView()
                                        .getCheckedItemPosition();
                                if (selectedPosition == 0) {
                                    buttonPusher.setDebugMode(true);
                                } else {
                                    buttonPusher.setDebugMode(false);
                                }
                            }
                        })
                .setNegativeButton(buttonPusher.getContext().getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.dismiss();
                            }
                        })
                .show();
        break;
    }
    case R.id.report_bugs: {
        Intent intent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", context.getResources().getString(R.string.email_addr), null));
        intent.putExtra(Intent.EXTRA_SUBJECT, context.getResources().getString(R.string.issue_subject));
        intent.putExtra(Intent.EXTRA_TEXT, context.getResources().getString(R.string.report_hint));
        context.startActivity(
                Intent.createChooser(intent, context.getResources().getString(R.string.issue_title)));
        break;
    }
    case R.id.open_source_components: {
        OpenSourceItemsDialog d = new OpenSourceItemsDialog(context);
        d.show();
        break;
    }
    case R.id.rate_app: {
        context.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=" + context.getApplicationContext().getPackageName())));
        break;
    }
    case R.id.about_app: {
        AboutDialog dialog = new AboutDialog(context);
        dialog.show();
        break;
    }
    }
    mDrawer.closeDrawers();
}

From source file:com.wit.android.support.content.intent.EmailIntent.java

/**
 *//*  w ww.j av  a2s.  co m*/
@Nullable
@Override
public Intent buildIntent() {
    if (mEmails == null || mEmails.size() == 0) {
        Log.e(TAG, "Can not create an EMAIL intent. No e-mail address/-es specified.");
        return null;
    }
    /**
     * Build the intent.
     */
    final Intent intent = new Intent(Intent.ACTION_SENDTO, createEmailUri(mEmails));
    intent.putExtra(Intent.EXTRA_SUBJECT, mSubject);
    intent.putExtra(Intent.EXTRA_TEXT, mMessage);
    if (mCcEmails != null) {
        intent.putExtra(Intent.EXTRA_CC, mCcEmails.toArray());
    }
    if (mccEmails != null) {
        intent.putExtra(Intent.EXTRA_BCC, mccEmails.toArray());
    }
    return intent;
}